1.对象与字符串之间的互转
String str = JSON.toJSONString(infoDo);
InfoDo infoDo = JSON.parseObject(strInfoDo, InfoDo.class);
2.对象集合与字符串之间的互转
String users = JSON.toJSONString(users);
List<User> userList = JSON.parseArray(userStr, User.class);
3.字符串互转JSONObject
JSONObject jsonObject = JSONObject.parseObject(jsonString);
JSONObject jsonObject = JSONObject.parseObject(str);
String jsonString = jsonObject.toJSONString();
4.map与字符串之间互转
JSONObject jsonObject = JSONObject.parseObject(str);
Map<String,Object> map = (Map<String,Object>)jsonObject;
String jsonString = JSON.toJSONString(map);
5.Map 转 Json对象
Map<String,Object> map = new HashMap<>();
map.put("age", 24);
map.put("name", "cool_summer_moon");
JSONObject json = new JSONObject(map);
Map<String,Object> map = (Map<String,Object>)jsonObject;