I can\'t figure out how to determine is an element that lives inside a json array is null. To check if the jsonObject itself is null, you simply use:
jsonObj
try JSONArray's method
public boolean isNull (int index)
In fact, it uses "null" string comparing to the content
JSONObject.NULL.equals(this.opt(index));
Try .isNull()
:
For your example:
if(!mapItem.isNull("date")) {
//Value is not null
}
However, to answer the title of this question, "how to tell if a JSONArray element is null", use .equals()
So, to check if index 1 is null:
if (!jsonArray.get(1).equals(null)) {
//jsonArray[1] is not null
}
I guess json passes null values as strings, so you can't check null as a java element. Instead treat the null value as a string as check this way:
if(!mapItem.getString("date").equals("null")) {
//Value is not null
}
I have updated the code snippet in the original question to a working version.