json 数据 转 java 对象
String json = "[{"id": "1","name": "zhangsan"}, {"id": "2","name": "lisi"}, {"id": "3","name": "wangwu"}]"; //json字符串 转 json 数组 JSONArray jsonarrr = JSONArray.parseArray(json); //json数组 转java对象 List<User> userlist = jsonarrr.toJavaList(User.class); String json = "{"id": "1","name": "zhangsan"}"; //json字符串 转 json 对象 JSONObject jsondx = JSONObject.parseObject(json); //json对象 转 java对象 User userlist = jsondx.toJavaList(User.class);
//转之前:[SysConfig(id=33), SysConfig(id=1), SysConfig(id=53)] //对象转json数组 String jsonCon = JSON.toJSONString(configList); //转之后:[{"id":33},{"id":1},{"id":53}]