map数据格式如下:
{
"msg":"success",
"code":200,
"data":{
"created":1560289612000,
"email":" abcd@qq.com",
"id":58,
"phone":"12345678901",
"updated":1560289612000,
"userName":"zhangsan"
}
}
获取map的中data 的数据转成对象
开始写是这样写的
String json = (String) map.get("data");
userEntity = new JSONObject().parseObject(json, UserEntity.class);
这样写提示: java.util.LinkedHashMap cannot be cast to java.lang.String
后面修改方法:先转成LinkedHashMap 再转成json最后转成json
LinkedHashMap linkedHashMap = (LinkedHashMap) map.get("data");
String json = new JSONObject().toJSONString(linkedHashMap);
userEntity = new JSONObject().parseObject(json, UserEntity.class);