Json字符串转换
jar包:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
Json
json转map
String jsonStr = "json字符串";
HashMap hashMap = JSON.parseObject("jsonStr", HashMap.class);
json转list
Object fullScoreObj = map.get("fullScore");
List<FullScoreTeacherVO> fullScoreList = JSONObject.parseArray(JSONArray.toJSONString(fullScoreObj), FullScoreTeacherVO.class);
json转 对象
Object examInfoObj = map.get("examInfo");
ExamInfoTeacherVO examInfo = JSONObject.parseObject(JSON.toJSONString(examInfoObj), ExamInfoTeacherVO.class);
Map
map转json
JSONObject json = new JSONObject(map);
map转 obj
User user = JSON.parseObject(JSON.toJSONString(map), User.class);
List
list转json
String str = JSON.toJSONString(userList);
Obj
对象转json
obj转Map
HashMap hashMap = JSON.parseObject(JSON.toJSONString(object), HashMap.class);
HashMap resultMap = JSON.parseObject(object.toString(), HashMap.class);
obj转List
List<String> list = JSON.parseObject(JSON.toJSONString(listObj),List.class) ;
String
String 转 JSON
JSONObject jsonObject = JSONObject.parseObject(jsonStr);