Here I am getting following JSON from local asset folder. All the JSON object is different in their name. Line 1, 3, 5, 7 .... upto 1000. Herewith I have attached the json for your reference.
{
"status": {
"rcode": 200,
"message": "OK"
},
"data": {
"0": {
"OutletName": "Test 1 ",
"Latitude": "16.123234",
"Longitude": "79.546745"
},
"1": {
"OutletName": "Test 2",
"Latitude": "16.343234",
"Longitude": "79.786745"
},
"2": {
"OutletName": "Test 3",
"Latitude": "19.1294",
"Longitude": "72.836122"
},
"3": {
"OutletName": "Test 4",
"Latitude": "19.136383",
"Longitude": "72.827997"
},
"6": {
"OutletName": "Test 5",
"Latitude": "19.136715",
"Longitude": "72.829248"
},
"7": {
"OutletName": "Test 6",
"Latitude": "19.128483",
"Longitude": "72.821199"
},
"8": {
"OutletName": "Test 7",
"Latitude": "19.128528",
"Longitude": "72.819388"
},
"10": {
"OutletName": "Test 8",
"Latitude": "19.140333",
"Longitude": "72.831095"
},
"11": {
"OutletName": "Test 9",
"Latitude": "19.14027",
"Longitude": "72.826285"
}
}
}
Here the Object name is different for all. So I try like this
private void parseJson() {
try {
JSONObject obj = new JSONObject(loadJSONFromAsset());
JSONObject jObj = obj.getJSONObject("data");
System.out.println("jObj.length()==> " + jObj.length());
for (int i = 0; i < jObj.length(); i++) {
if (jObj.has(String.valueOf(i)) && !jObj.isNull(String.valueOf(i))) {
JSONObject jObj1 = jObj.getJSONObject(String.valueOf(i));
System.out.println("Index==> "+i);
System.out.println("OutletName==> "+jObj1.getString("OutletName"));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
But here I not getting all the data. Please help me to parse this kind of JSON.
Thanks in advance.