alibaba Json的jar包的下载与使用

http://mvnrepository.com/artifact/com.alibaba/fastjson/1.2.45

 

  JSONObject result = JSONObject.parseObject(json);
	Map map=new HashMap();
		map.put("total", total);
		map.put("rows", list);
		JSONObject result = JSONObject.parseObject(JSON.toJSONString(map)); 

 

 Stu stu=new Stu();
        stu.setAge(18);
        stu.setName("小王");
       List listStu=new ArrayList();
       Stu stu2=new Stu();
       stu2.setAge(18);
       stu2.setName("小王");
       listStu.add(stu2);
       stu.setStuList(listStu);
       JSONObject json1=JSONObject.parseObject(JSON.toJSONString(stu));
       List list = (List)json1.get("stuList");

 

JSONArray objects = JSONObject.parseArray("");

 

//ss转map,map转数组
        String ss="[{\"total\":1,\"size\":5}]";
        String dd=ss.replaceAll(",","},{");
        System.out.println(dd);
        List list = JSONObject.parseArray(dd);
        System.out.println(list.get(0));
        Map maps = (Map)JSON.parse(ss);  
        System.out.println(maps);

 

 

 

你可能感兴趣的:(工具类)