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<Stu> listStu=new ArrayList<Stu>();
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<String,Object> maps = (Map)JSON.parse(ss);
System.out.println(maps);
更多推荐
所有评论(0)