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()); } }
编程学习交流群
QQ群:168703370
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步