Json把String转对象、转list。把对象转json
1,Json把String转对象
| public Object test(String jsonStr){ |
| JSONArray jsonArray = JSON.parseArray(jsonStr); |
| StudentVo studentVo = (StudentVo) JSONObject.parseArray(jsonArray.toJSONString(), StudentVo.class); |
| return models; |
| } |
复制
2,Json把String转List
| public Object test(@RequestBody Map<String, Object> map){ |
| String json1 = JSON.toJSONString(models.get("regionInfos")); |
| |
| List<RegionInfo> znjsRegionInfos = JSON.parseArray(json1, RegionInfo.class); |
| return models; |
| } |
复制
3,对象转JSON
| String jsonObjectStr = JSONObject.toJSONString(studentList); |
| 或 |
| String jsonObjectStr = JSON.toJSONString(studentList); |
复制