首页 > 代码库 > 解析json数组

解析json数组

1 String json = "[{code:0,message:\‘success or error\‘,id:\"0001\",name:\"pic.jpg\"},{code:0,message:\‘success or error\‘,id:\"0001\",name:\"pic.jpg\"},{code:0,message:\‘success or error\‘,id:\"0001\",name:\"pic.jpg\"}]";
2 net.sf.json.JSONArray jsonArr = net.sf.json.JSONArray.fromObject(jsonData);
3         for(int i=0;i<jsonArr.size();i++){
4             net.sf.json.JSONObject job = jsonArr.getJSONObject(i); // 遍历 jsonarray 数组,把每一个对象转成 json 对象
5             System.out.println(job.get("name"));
6             System.out.println(job.get("url"));
       }

 

解析json数组