0
"BRAZIL": {

   "channel": "brazil_ch",        
    "city": {
            "Belo Horizonte": "belohorizonte_ch_org",
            "Brasilia": "brasilia_ch_org",
            "Curitiba": "curitiba_ch_org",
            "Fortaleza": "fortaleza_ch_org",
            "Porto Alegre": "portoalegre_ch_org",
            "Recife": "recife_ch_org",
            "Rio De Janeiro": "rio_ch_org",
            "Salvador, Bahia": "salvador_ch_org",
            "Sao Paulo": "saopaulo_ch_org"
        }

    }

This is my JSON. I need to retrieve the channel value in Brazil and also city values. Please help me.

Thanks in Advance.

mehrdad khosravi
  • 2,228
  • 9
  • 29
  • 34
Ratna
  • 33
  • 7

1 Answers1

0
JSONObject jsonObject = new JSONObject(jsonString);
String channel = jsonObject.getJSONObject("BRAZIL").getString("channel");
JSONArray jsonArray = jsonObject.getJSONObject("BRAZIL").getJSONArray("city");
int length = jsonArray.length();
String[] cities = new String[length];
for (int i = 0; i < length; i++) {
    String city = jsonArray.getString(i);
    cities[i] = city;
}
okarakose
  • 3,692
  • 5
  • 24
  • 44