Skip to content Skip to sidebar Skip to footer

Json To Array List Conversion

Below is my json code, I can't convert it to arraylist: {'location':[{'place_name':'Arabian Ranches ,Dubai Land'},{'place_name':'The Greens & The Views ,Emirates Living'},{'pla

Solution 1:

in here location is a JsonArray object. so use an integer variable for access data from it :)

ArrayList<String> data=newArrayList<String>();
for(int i=0;i<location.length();i++){
    JSONObject arrayElement=location.getJSONObject(i);
    data.add(arrayElement.getString("place_name"));
    Log.i("json",data.get(i));
    }

Solution 2:

change Log.d(location.getJSONObject("place_name"));

to

Log.d(location.getJSONObject(i).getString("place_name");

Post a Comment for "Json To Array List Conversion"