转换JSONarray到ArrayList中JSONarray、ArrayList

2023-09-12 22:06:06 作者:一點點可愛

我下载一个JSON字符串,并将其转换成JSONArray。林把它变成一个列表视图,并需要能够从该列表视图后删除,因为JSONArray没有卸下摆臂方法(感谢奥巴马),我试图将其转换为一个ArrayList

下面是我的JSON(与Array.toString()):

  [{thumb_url:TB-1370913834.jpg,事项标识:15,伯爵:44,event_tagline:这是一个标语,EVENT_NAME:5岁生日,event_end:1370919600,event_start:1370876400}]
 

我需要得到它到一个数组中,并能够通过各自的键来调用字符串。鸭preciate任何帮助!

解决方案

 的ArrayList<字符串>的ListData =新的ArrayList<字符串>();
JSONArray jArray =(JSONArray),其中的JSONObject;
如果(jArray!= NULL){
   的for(int i = 0; I< jArray.length();我++){
    listdata.add(jArray.get(ⅰ)的ToString());
   }
}
 
关于FastJson中jsonArray转换成list集合的方法

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!

解决方案

ArrayList<String> listdata = new ArrayList<String>();     
JSONArray jArray = (JSONArray)jsonObject; 
if (jArray != null) { 
   for (int i=0;i<jArray.length();i++){ 
    listdata.add(jArray.get(i).toString());
   } 
}