Andi
Andi

Reputation: 119

Handling null in JSON RESPONSE

I am getting json response as

["L500","Success",null]

How can I handle it

Here is what I tried

jsonArray.getJSONArray(2).getJSONObject(2).equals(JSONObject.NULL);

However, it produces the error:

org.json.JSONException: Value null at 2 of type org.json.JSONObject$1 cannot be converted to JSONArray

If null I need to show a Toast message to user something like "No records found".

Upvotes: 0

Views: 494

Answers (1)

Andi
Andi

Reputation: 119

I solved it by replacing

jsonArray.getJSONArray(2).getJSONObject(2).equals(JSONObject.NULL);

with

jsonArray.get(2).equals(null);

Upvotes: 1

Related Questions