# 以实体类User 为例
User user =newUser();Map<String,Object> map =newHashMap<>();
# Map转为实体类
User user = JSON.parseObject(JSON.toJSONString(map),User.class);
# 实体类转为MapMap newMap = JSON.parseObject(JSON.toJSONString(user),Map.class);
二、JSONObject和实体类之间的转换
# 以实体类User 为例
User user =newUser();JSONObject jsonObject =newJSONObject();
# JSONObject转为实体类
User user = JSON.parseObject(JSON.toJSONString(jsonObject),User.class);
# 实体类转为JSONObjectJSONObject newJSONObject =JSONObject.parseObject(JSONObject.toJSONString(user));JSONObject newJSONObject = JSON.parseObject(JSON.toJSONString(user),JSONObject.class);