简体   繁体   中英

Nested JSON parsing in android using url

I am new to JSON parsing and I am stuck in this nested JSON parsing.Here is the attached JSON data for one city only which I get from the url :

{
"CityCode": 142,
"CityName": "Yavatmal",
"State": {
"StateCode": 21,
"StateName": "Maharashtra",
"CountryCode": 1,
"Country": {
  "CountryCode": 1,
  "CountryName": "India",
  "IsdCode": "+91"
}
},
"Country": {
"CountryCode": 1,
"CountryName": "India",
"IsdCode": "+91"
},
"GPlaceId": "ChIJ3U60i8zo0zsR4L7sQeqtd0g",
"Latitude": 20.388794,
"Longitude": 78.120407,
"ActiveStatus": 1
}

Can anyone tell me how to parse this type of JSON data in such a way that I can display each key in a textView.

the scope sorrounded by "{" "}" are called json object. You can extract like `

String jsonData = ""//received json string    
jsonObject obj = new JSONSObject(jsonData);`
obj.getString("CityCode");
obj.getJSONObject("state");

if the key hold the single value , then you can get that in string. If the key itself hold another jsonobject , extract that into separate jsonobject and repeat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM