json类型的数据转对象,(Map对象)
ObjectNode datanode_temp = IMUsers.getIMUsersByUserName(userId);
Map<?, ?> map = JSON.parseObject(String.valueOf(datanode_temp), Map.class);
List<?> list = (List<?>) map.get("entities");
if (null != list && list.size() != 0) {
Map<?, ?> map_user = JSON.parseObject(String.valueOf(list.get(0)), Map.class);
System.out.println(map_user.get("username"));
}
datanode_temp={"action":"get","path":"/users","uri":"http://a1.easemob.com/users/HYS003042","entities":[{"uuid":"b6f2c0aa-bf1c-11e5-a611-7b21d18e06a3","type":"user","created":1453256575402,"modified":1453256575402,"username":"HYS003042","activated":true}],"timestamp":1453256900064,"duration":1,"count":1,"statusCode":200}
2.json字符串转对象
User user= JSONObject.parseObject(userStr,User.class);
public void jsonObject(JSONObject jsonObject){ JSONObject userObject = jsonObject.getJSONObject("user"); User user = JSONObject.toJavaObject(userObject,User.class); }