读取ArrayList <string>键:值

时间:2016-02-25 18:15:11

标签: java

我有一个使用这种格式的ArrayList:

 [{"id":"480","value1":"xxx","value2":"yy"},{"id":"200","value1":"123abc","value2":"bbb"},{"id":"520","value1":"qwewer","value2":"eeee"}]

ArrayList<String> result = task.execute(itensUrl).get();
        for(int i = 0 ; i < result.size() ; i++) {
            ArrayList<String> currentList = result.get(i);

            for (int j = 0; j < currentList.size(); j++) {
                String s = currentList.get(1);
            }
        }

但我有这个错误:

不兼容的类型 - 必需的java.util.Arraylist - 发现:java.lang.String

1 个答案:

答案 0 :(得分:0)

感谢大家的帮助,结果就是这样:

 ArrayList<String> result = task.execute(itensUrl).get();
        for(int i = 0 ; i < result.size() ; i++) {
            String currentList = result.get(i);
            JSONObject jsonobject = new JSONObject(currentList);

            String id=jsonobject.optString("id");
            String value1=jsonobject.optString("name_user_feed");
            String value2=jsonobject.optString("establishment");
            System.out.println("id="+id);
            System.out.println("value1="+value1);
            System.out.println("value2=" +value2);

        }