JSON-java

 

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

 

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name", "小明");
        jsonObject1.put("sex", "男");
        jsonObject1.put("age", "11");
        
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name", "小红");
        jsonObject2.put("sex", "nv");
        jsonObject2.put("age", "15");
        jsonObject2.put("data", "{'sex':'女'}");
        
        JSONArray jsonArray1 = new JSONArray();
        jsonArray1.put(jsonObject1);
        jsonArray1.put(jsonObject2);
        
        System.out.println("jsonArray1:"+jsonArray1);
        System.out.println("jsonArray1.get(1):"+jsonArray1.get(1));
        
        JSONObject jsonObject3 = JSONObject.fromBean(jsonArray1.get(1));
        System.out.println("jsonObject3.get('sex'):"+jsonObject3.get("sex"));
        System.out.println("jsonObject3.get('data'):"+jsonObject3.get("data"));
        
        JSONObject jsonObject4 = JSONObject.fromBean(jsonObject3.get("data"));
        System.out.println("jsonObject4.get('sex'):"+jsonObject4.get("sex"));

 

posted on 2017-12-20 14:01  研者  阅读(172)  评论(0编辑  收藏  举报