Converting JSONarray to ArrayList

TheGeekNess picture TheGeekNess · Jun 11, 2013 · Viewed 300.2k times · Source

I am downloading a JSON string and converting it to JSONArray. Im putting it into a listview and need to be able to delete from that listview later, and since JSONArray has no .remove method (Thanks Obama), I am trying to convert it to an arraylist.

here is my JSON (the array.toString()):

[{"thumb_url":"tb-1370913834.jpg","event_id":"15","count":"44","event_tagline":"this is a tagline","event_name":"5th birthday","event_end":"1370919600","event_start":"1370876400"}]

I need to get it into an array and be able to call the strings by their respective keys. Appreciate any help!

Answer

Sagar Maiyad picture Sagar Maiyad · Jun 11, 2013
ArrayList<String> listdata = new ArrayList<String>();     
JSONArray jArray = (JSONArray)jsonObject; 
if (jArray != null) { 
   for (int i=0;i<jArray.length();i++){ 
    listdata.add(jArray.getString(i));
   } 
}