Reputation: 11201
I can't understand why this code is crashing, I have this response from my server:
[{
"parking1": "Plaza de la Estacion",
"parking2": "",
"takeDate": "2012-12-11 11:00:48",
"returnDate": null,
"time": null,
"cost": "0.00"
}]
I convert this into a JSONObject
and check if returnDate
is null:
JSONObject json_data = jArray.getJSONObject(0);
if (json_data.getString("returnDate") == null) {
}
But this condition is never true. How should it be checked if null?
Upvotes: 1
Views: 113
Reputation: 3512
Try
JSONObject json_data = jArray.getJSONObject(0);
if (json_data.opt("returnDate") == null) {
}
Upvotes: 0
Reputation: 15973
You can check if a json entry is null using:
if(json_data.isNull("returnDate")) {
}
Upvotes: 3