1

我不明白为什么这段代码会崩溃,我的服务器有这个响应:

    [{
        "parking1": "Plaza de la Estacion",
        "parking2": "",
        "takeDate": "2012-12-11 11:00:48",
        "returnDate": null,
        "time": null,
        "cost": "0.00"
    }]

我将其转换为 aJSONObject并检查是否returnDate为空:

JSONObject json_data = jArray.getJSONObject(0);
if (json_data.getString("returnDate") == null) {
}

但这种情况永远不会成立。如果为null,应该如何检查?

4

2 回答 2

3

您可以使用以下方法检查 json 条目是否为空:

if(json_data.isNull("returnDate")) {
}
于 2012-12-11T10:11:21.640 回答
0

尝试

JSONObject json_data = jArray.getJSONObject(0);
if (json_data.opt("returnDate") == null) {
}
于 2012-12-11T10:15:47.750 回答