I've lots of json array which are formatted in this way:
[
{
"cod_ent":"953",
"name_ent":"example1",
"amb":{
"15":{
"cod_amb":"002",
"name_amb":"Or11"
},
"1723":{
"cod_amb":"00009",
"name_amb":"P3o1"
}
}
}
]
and i'd like to read it correctly in android. I try with this code and i manage to retrieve the first two entries ("cod_ent" and "name_ent") but i'm still not able to manage "amb" sub-array.
JSONObject json = null;
try {
InputStream pre_json = response.getEntity().getContent();
json = new JSONObject("{data:"+convertStreamToString(pre_json)+"}");
} catch (IOException e) {
e.printStackTrace();
}
JSONArray jsonArray = json.getJSONArray("data");
for (int i = 0; i < jsonArray.length(); i++){
JSONObject getfromarray = jsonArray.getJSONObject(i);
cod_ent = getfromarray.getString("cod_ent");
name_ent = getfromarray.getString("name_ent");
//how to get amb???
}