Am new to using json files and I have constructed a layered json object and i am trying to display the values in android studio Toast but some of the values which are key and I don't want them to be displayed yet but they are getting displayed in the process please guide on what am doing wrong
This is portion of the json file (single object in the json array)
{
"county": "Nyeri",
"subcounty": ["Kieni East", [{
"ward": ["funny", [{
"policestation": ["null"]
}], "kkkkk", [{
"policestation": ["null"]
}]]
}], "Kieni West", [{
"ward": "null"
}], "Mathira East", [{
"ward": ["Magutu", [{
"policestation": ["Magutu", [{
"arbitrator": ["null"]
}], "Magutu ps", [{
"arbitrator": ["null"]
}], "Kagochi PS", [{
"arbitrator": ["null"]
}]]
}], "Iriani", [{
"policestation": ["null"]
}], "Konyu", [{
"policestation": ["null"]
}], "Kirimukuyu", [{
"policestation": ["null"]
}], "Karatina Town", [{
"policestation": ["Kagochi PS", [{
"arbitrator": ["null"]
}], "Gitunduti PS", [{
"arbitrator": ["christopher bundi", "silvester kasanga"]
}]]
}]]
}], "Mukurweini", [{
"ward": "null"
}], "Tetu", [{
"ward": ["rulie", [{
"policestation": ["null"]
}]]
}]]
}
This is the code and trying to access the subcounties with excluding the keys to the wardslist
try {
JSONArray jsonArray = new JSONArray (response);
for (int i = 0; i < jsonArray.length (); i++) {
JSONObject jsonObject = jsonArray.getJSONObject (i);
String subcounty = jsonObject.getString ("subcounty");
Toast.makeText (getApplicationContext (), subcounty, Toast.LENGTH_LONG).show ();}//close try and catch follows
The challenge is to select the subcounty value exempting those values that are key to ward. Thank as you offer support