{
"queryorders_result": "{\"data\":[{\"SplitType\":3,\"cosPrice\":0,\"details\":[{\"firstLevle\":1316,\"productId\":1294340891,\"quantity\":1,\"secondLevel\":1381,\"thirdLevle\":1391,\"totalPrice\":138,\"wareId\":1715748194,\"ygCosFee\":110.4}],\"orderId\":13966560746,\"orderTime\":\"2016-04-01 15:21:59\",\"parentId\":0,\"popId\":157021,\"sourceEmt\":1,\"totalMoney\":138,\"yn\":0},{\"SplitType\":3,\"cosPrice\":0,\"details\":[{\"firstLevle\":1316,\"productId\":1294340891,\"quantity\":1,\"secondLevel\":1381,\"thirdLevle\":1391,\"totalPrice\":138,\"wareId\":1715748194,\"ygCosFee\":110.4}],\"orderId\":13946016040,\"orderTime\":\"2016-04-01 15:20:32\",\"parentId\":0,\"popId\":157021,\"sourceEmt\":1,\"totalMoney\":138,\"yn\":0},{\"SplitType\":3,\"cosPrice\":0,\"details\":[{\"firstLevle\":6144,\"productId\":1003881889,\"quantity\":1,\"secondLevel\":6182,\"thirdLevle\":6192,\"totalPrice\":29,\"wareId\":1014999404,\"ygCosFee\":23.2}],\"orderId\":13966538562,\"orderTime\":\"2016-04-01 15:18:26\",\"parentId\":0,\"popId\":31689,\"sourceEmt\":1,\"totalMoney\":29,\"yn\":0}]}"
}
想要解析出 details
各位大神帮忙啦
你先定义类,然后使用Gson的fromJson方法转换成类。 下面是我的代码: public class showapi_res_body { private cityInfo cityInfo = new cityInfo(); private f1 f1 = new f1(); @Override public String toString() { return "showapi_res_body [cityInfo=" + cityInfo.toString() + ", f1=" + f1.toString() + "]"; } } public class day_weather_pic { private int night_air_temperature = 19; private String night_weather = "多云"; @Override public String toString() { return "day_weather_pic [night_air_temperature=" + night_air_temperature + ", night_weather=" + night_weather + "]"; } } public class f1 { private String day="20150906"; private int day_air_temperature=3; private String day_weather= "晴"; private day_weather_pic day_weather_pic = new day_weather_pic(); @Override public String toString() { return "f1 [day=" + day + ", day_air_temperature=" + day_air_temperature + ", day_weather=" + day_weather + ", day_weather_pic=" + day_weather_pic.toString() + "]"; } } public class cityInfo { private String c2 ="lanzhou"; private String c3 ="兰州"; @Override public String toString() { return "cityInfo [c2=" + c2 + ", c3=" + c3 + "]"; } } public class showapi { private int showapi_res_code = 0; private String showapi_res_error = ""; private showapi_res_body showapi_res_body = new showapi_res_body(); @Override public String toString() { return "showapi [showapi_res_code=" + showapi_res_code + ", showapi_res_error=" + showapi_res_error + ", showapi_res_body=" + showapi_res_body.toString() + "]"; } } public class test { public static void main(String[] args) { showapi anObject = new showapi(); Gson gson = new Gson(); String json = gson.toJson(anObject); System.out.println(json.toString()); showapi a = gson.fromJson(json, showapi.class); System.out.println(a.toString()); } } 运行后输出的日志: {"showapi_res_code":0,"showapi_res_error":"","showapi_res_body":{"cityInfo":{"c2":"lanzhou","c3":"兰州"},"f1":{"day":"20150906","day_air_temperature":3,"day_weather":"晴","day_weather_pic":{"night_air_temperature":19,"night_weather":"多云"}}}} showapi [showapi_res_code=0, showapi_res_error=, showapi_res_body=showapi_res_body [cityInfo=cityInfo [c2=lanzhou, c3=兰州], f1=f1 [day=20150906, day_air_temperature=3, day_weather=晴, day_weather_pic=day_weather_pic [night_air_temperature=19, night_weather=多云]]]]
答案来源网络,供参考,希望对您有帮助
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。