List<SysUser> suList = new ArrayList<>(); Map<String,Object> suMap = new HashMap<>(); for(int i = 0 ; i<3; i++){ SysUser su = new SysUser(); su.setId(1); su.setRoleId(2); su.setUserPhone("phone"+i); suList.add(su); } //Map对象转成JSON对象 suMap.put("suList",suList); JSONObject ms = JSONObject.parseObject(JSONObject.toJSONString(suMap)); JSONArray suListMap = ms.getJSONArray("suList"); String suListMapStr = suListMap.toString(); System.out.println("Map对象转换后的字符串="+suListMapStr); //List对象转成JSON对象 JSONArray js = JSONArray.parseArray(JSONObject.toJSONString(suList)); String s = js.toJSONString(); System.out.println("List对象转换后的字符串="+s); // //JSONObject 转化成List对象 ArrayList<SysUser> suArr = JSON.parseObject(s,new TypeReference<ArrayList<SysUser>>(){}); System.out.println("JSONObject 转化成List对象"+suArr.size());
fastJSON List对象 Map对象与JSON对象的互转
最新推荐文章于 2024-07-20 03:10:13 发布