json--对象互转

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);
}




转载于:https://www.cnblogs.com/jeofey/p/7227010.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值