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());
}
}
java alibaba fastJson 遍历数组json
点赞
收藏