Jzon Charles Jzon Charles - 1 month ago 19
JSON Question

JSON PARSING ARRAY

enter image description here

I'm new here in stack overflow please help me please....
how can i parse this array in my android? this is my android code

private Boolean parseData(){

try{

JSONArray ja = new JSONArray(jsonData);
JSONObject jo = null;

wantedLists.clear();
WantedList wantedList;

for(int i = 0; i<ja.length(); i++){

jo = ja.getJSONObject(i);
String lastname=jo.getString("lastname");
String alyas=jo.getString("alyas");
String reward=jo.getString("reward");
String authority=jo.getString("authority");
String location_name=jo.getString("location_name");
String firstname=jo.getString( "firstname" );
String middlename=jo.getString( "middlename" );
String imageUrl=jo.getString("url");
wantedList = new WantedList();

wantedList.setLastname(lastname);
wantedList.setAlyas(alyas);
wantedList.setAuthority(authority);
wantedList.setReward(reward);
wantedList.setLocation_name(location_name);
wantedList.setFirstname( firstname );
wantedList.setMiddlename( middlename );
wantedList.setImageUrl(imageUrl);


wantedLists.add(wantedList);
}

Answer

Your JSON uses middlename with an uppercase 'M':

"Middlename": "Lumbres",

But your JSON parser uses middlename with a lowercase 'm':

String middlename=jo.getString( "middlename" );

That should throw a org.json.JSONException: No value for middlename error.

Either modify your app's JSON parser to get "Middlename" or modify the JSON response (if you control the server or module that spits out the response) to use "middlename".

Comments