java如何解析json 格式的字符串?

java如何解析json 格式的字符串


泛舟湖上清波郎朗
浏览 439回答 1
1回答

慕侠2389804

public static void main(String[] args){String temp="{'data':{'a':[{'b1':'bb1','c1':'cc1'},{'b2':'bb2','c2':'cc2'}]}}";JSONObject jodata =JSONObject.fromObject(temp);JSONObject joa =JSONObject.fromObject(jodata.get("data").toString());JSONArray ja=JSONArray.fromObject(joa.get("a"));for(int i=0;i<ja.size();i++){JSONObject o=ja.getJSONObject(i);if(o.get("b1")!=null){System.out.println(o.get("b1"));}if(o.get("c1")!=null){System.out.println(o.get("c1"));}if(o.get("b2")!=null){System.out.println(o.get("b2"));}if(o.get("c2")!=null){System.out.println(o.get("c2"));}}}注:要包含两个jar包ezmorph-1.0.6.jar和json-lib-2.2.2-jdk15.jar,jar包在附件中
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java