How to check if JSONArray Element is null

前端 未结 3 467
渐次进展
渐次进展 2020-12-11 02:25

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         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 03:06

    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
    }
    

提交回复
热议问题