标签:get com success imp oid parse ack col size
web service返回json字符串后需要解析,举例如下:
package com.glaway.offline.test.main; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; public class JsonTest { public static void main(String[] args) { test1(); } /** * 解析json字符串 */ public static void test1(){ String json = "{\"code\":\"success\",\"data\":[{\"age\":25,\"name\":\"1\"},{\"age\":8,\"name\":\"2\"}]}"; if(json != null){ JSONObject jsonObject = JSONObject.parseObject(json); if(jsonObject.get("code") != null){ String code = (String) jsonObject.get("code"); if(code.equals("success")){ JSONArray jsonArray = (JSONArray) jsonObject.get("data"); if(jsonArray != null){ for(int i=0;i<jsonArray.size();i++){ JSONObject object = jsonArray.getJSONObject(i); String name = (String) object.get("name") != null?(String) object.get("name"):null; Integer age = object.get("age")!=null?(Integer)object.get("age"):null; System.out.println(name+":"+age); //1:25、2:8 } } } } } } }
标签:get com success imp oid parse ack col size
原文地址:https://www.cnblogs.com/wf2010517141/p/10852326.html