Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.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_Android - Fatal编程技术网

Java 当JSON对象不';我没有价值的钥匙

Java 当JSON对象不';我没有价值的钥匙,java,android,Java,Android,我有一个对象,它需要4个参数来设置JSONObject中的值。但是,当我从JSONObject调用get(String name)时,它有3个值,因此抛出一个JSONException。以下是一个例子: "JSON":{ "aaa":"111", "bbb":"111", "ddd":"111" } 如果JSON键不存在,如何为值设置null。。不要像这样使用GSON: if (jsonObject.has("aaa") { this.aaa = jsonObj

我有一个对象,它需要4个参数来设置
JSONObject
中的值。但是,当我从
JSONObject
调用
get(String name)
时,它有3个值,因此抛出一个
JSONException
。以下是一个例子:

"JSON":{
    "aaa":"111",
    "bbb":"111",
    "ddd":"111"
}
如果JSON键不存在,如何为值设置
null
。。不要像这样使用GSON:

if (jsonObject.has("aaa") {
    this.aaa = jsonObject.getString("aaa");
}

就把那个对象的键设成一个空字符串吧?我不能设置它。我只是一个为JSON值创建对象并发送它的接收者;如果(jsonObject.has(“test”){this.test=jsonObject.getString(“test”);}否则{test=”“;}可以吗?@Christian