Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 取消搜索带有空字段的JSON_Java_Json_Gson - Fatal编程技术网

Java 取消搜索带有空字段的JSON

Java 取消搜索带有空字段的JSON,java,json,gson,Java,Json,Gson,我正在尝试反序列化JSON对象,如下所示: public class Example { private String a; private int b; private SubDataExample c; //more fields, constructor, getters, etc } public class SubDataExample{ private String d; private int e; //more fields, constructor, gett

我正在尝试反序列化JSON对象,如下所示:

public class Example { 
private String a; 
private int b; 
private SubDataExample c; 
//more fields, constructor, getters, etc
} 

public class SubDataExample{ 
private String d; 
private int e; 
//more fields, constructor, getters, etc 
} 
它在大多数情况下都能很好地工作,但有时子数据不会带来任何影响 数据,我得到的JSON如下:

{"a":"blabla", b:843849, c:""}
然后,GSON失败,我得到一个异常。有可能填补 反序列化对象中的“c”字段是否为空

我正在使用一个我还没有制作的Web服务,因此,我别无选择 关于更改必须反序列化的JSON

谢谢你的帮助


非常感谢

我希望如果没有
子数据示例
,那么您应该

{ "a": "blabla", "b": 843849, "c": null }


你是对的。出现的JSON格式确实不正确,因此,Gson显然失败了。因此,如果这是正确的答案,您应该接受答案,然后单击“^”(“此答案很有用”)。
{ "a": "blabla", "b": 843849 }