I have one url, I want to take these data and show it into list view using JSON, but when I run it, there's something error, that said :
JSONArray cannot be converted to JSONObject
This is my code:
JSONArray jsonArray = new JSONArray ();
for (int i = 0; i < jsonArray.length(); i++) {
JSONArray innerJsonArray = jsonArray.getJSONArray(i);
JSONObject c = innerJsonArray.getJSONObject(0);
HashMap<String, String> map = new HashMap<String, String>();
// Storing each json item in variable
map.put("atasan", c.get("atasan").toString());
map.put("kode_agen", c.get("kode_agen").toString());
map.put("jenis", c.get("jenis").toString());
map.put("no_aaji", c.get("no_aaji").toString());
map.put("nama_agen", c.get("nama_agen").toString());
AgenList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, AgenList, R.layout.list_item,
new String[] {ATASAN, KODE_AGEN, JENIS, NO_AAJI, NAMA_AGEN}, new int [] {R.id.atasan, R.id.kode_agen, R.id.jenis, R.id.no_aaji, R.id.nama_agen});
setListAdapter(adapter);
I don't know where's my fault, I hope somebody can help me to solve this problem ?
this is the example data that i want to take : {"atasan":"THOMAS SUNARDI ", "kode_agen":"024932", "jenis":"Regional","no_aaji":"11529943* " ,"nama_agen":"YONATHAN ADRIYANTO WIDJAJA"}