java alibaba fastJson 遍历数组json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.*;
import com.alibaba.fastjson.*;
public class Test {
    public static void main(String[] args) {
        //方法1
        String json = "[{\"companyId\":\"111111111\",\"companyName\":\"Huuuu\",\"_uid\":10,\"_index\":0,\"_state\":\"modified\"},{\"companyId\":\"000000000000000000\",\"companyName\":\"cx01\",\"_uid\":11,\"_index\":1,\"_state\":\"modified\"},{\"companyId\":\"9999999999999\",\"companyName\":\"ttt\",\"_uid\":12,\"_index\":2,\"_state\":\"modified\"}]";
        List<HashMap> list =JSON.parseArray(json, HashMap.class);
        for(int i=0;i<list.size();i++){
          System.out.println(list.get(i).get("companyId"));;
        }
        //方法2
        /*
        JSONArray jarr = JSONArray.parseArray(json);
        for (Iterator iterator = jarr.iterator(); iterator.hasNext();) {
          JSONObject job = (JSONObject) iterator.next();
          System.out.println(job.get("companyId").toString());
        }*/
    }
}

 

复制代码
    String str = "[\"\\/static\\/upload\\/1539863638_0.png\"]";
    JSONArray array = new JSONArray().parseArray(str);

        if(null!=array){
            array.set(0, "----------"+array.get(0));
            for (Iterator iterator = array.iterator(); iterator.hasNext();) {
              System.out.println(iterator.next());
            }
        }
复制代码

 

posted @   小崔开发  阅读(17542)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示