I am getting JSON string from my server. I have data which looks like this (JSON Array)
{
"result": {
"response": {
"data": [
{
"identification": {
"id": null,
"number": {
"default": "IA224",
"alternative": null
},
"callsign": null,
"codeshare": null
}
}
]
}
}
}
but some times this data can be (JSON object) or be null if l entered wrong information
data : null
I want to do different operations when its object and different when its an array. I am getting following exception
Caused by: org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONArray
l did this code but he dose not work
val jsonArray = JSONArray(response.get("data").toString())
if(jsonArray.isNull(0)){
jsonArray.getJSONObject(0).getString("data");
}