I am trying to parse a JSON Array But I Dont know how to parse such Array. Please explain the concept when you write the code
{
"snappedPoints": [
{
"location": {
"latitude": -35.2784167,
"longitude": 149.1294692
},
"originalIndex": 0,
"placeId": "ChIJoR7CemhNFmsRQB9QbW7qABM"
},
{
"location": {
"latitude": -35.280321693840129,
"longitude": 149.12908274880189
},
"originalIndex": 1,
"placeId": "ChIJiy6YT2hNFmsRkHZAbW7qABM"
},
{
"location": {
"latitude": -35.280960897210818,
"longitude": 149.1293250692261
},
"originalIndex": 2,
"placeId": "ChIJW9R7smlNFmsRMH1AbW7qABM"
},
{
"location": {
"latitude": -35.28142839817933,
"longitude": 149.1298619971291
},
"originalIndex": 3,
"placeId": "ChIJy8c0r2lNFmsRQEZUbW7qABM"
},
{
"location": {
"latitude": -35.28193988170618,
"longitude": 149.13001013387623
},
"originalIndex": 4,
"placeId": "ChIJ58xCoGlNFmsRUEZUbW7qABM"
},
{
"location": {
"latitude": -35.282819705480151,
"longitude": 149.1295597114644
},
"originalIndex": 5,
"placeId": "ChIJabjuhGlNFmsREIxAbW7qABM"
},
{
"location": {
"latitude": -35.283139388422363,
"longitude": 149.12895618087012
},
"originalIndex": 6,
"placeId": "ChIJ1Wi6I2pNFmsRQL9GbW7qABM"
},
{
"location": {
"latitude": -35.284728724835304,
"longitude": 149.12835061713685
},
"originalIndex": 7,
"placeId": "ChIJW5JAZmpNFmsRegG0-Jc80sM"
}
]
}
can someone please write the code for this one and explain it?
Thanks in advance
I Tried this one for testing whether it fetch records or not?
JSONArray array = null;
try {
array = new JSONArray("snappedPoints");
for(int i =0; i<= array.length();i++) {
JSONObject object = array.getJSONObject(i);
String Location = (String) object.get("latitude");
Toast.makeText(MainActivity.this, Location, Toast.LENGTH_SHORT).show();
Log.e("============" ,Location );
}
} catch (JSONException e) {
e.printStackTrace();
}