l am try to build simple app provide flight schedule . the problem is l have many object in json url and the array list inside of these object and l cant to get array list from objects because l got error fatal Caused by: org.json.JSONException: Value
my data json api
{
"result": {
"response": {
"airport": {
"pluginData": {
"schedule": {
"arrivals": {
"data": [
{
"flight": {
"identification": {
"id": null,
"row": 4832637003,
"number": {
"default": "ZP4801",
"alternative": null
},
"callsign": null,
"codeshare": null
}
}
}
]
}
}
}
}
}
}
}
my code for getting data json of array list
private fun handleJson (jsonString: String?){
val jsonArray = JSONArray(jsonString)
val list = ArrayList<FlightShdu>()
var x = 0
while (x < jsonArray.length()){
val jsonObject = jsonArray.getJSONObject(x)
list.add(FlightShdu(
jsonObject.getInt("id"),
jsonObject.getString("callsign")
))
x++
}
val adapter = ListAdapte(this@MainActivity,list)
flightShdu_list.adapter = adapter
}
val jsonArray = JSONArray(jsonString). JSON arrays start with[. Your JSON start with{. So it's an object, not an array.data [1]you can take look in my link [jsoneditoronline.org/?id=38a83e0996cd4d1a823a55755907c629]{, this is a JSONObject, too. So you can access its unique property named ""airport". Repeat until you reach the property named "data". Its value starts with a[, so it's an array this time, not an object. Its first element, at index 0, starts with a{, so it's once again an object. You should now get the idea.