json转换

JSONObject roomInfoData = JSONObject.fromObject("{'ladder':4,'type':8,'round':10,'playernum':5,'sel1':[1,2,3]}");


com.youchao.pb.CommonPb.Room.Builder rb = com.youchao.pb.CommonPb.Room.newBuilder();
rb.setType(roomInfoData.getInt("type"));
rb.setLimit(1);
rb.setLadder(roomInfoData.getInt("ladder"));
rb.setPlayernum(roomInfoData.getInt("playernum"));
rb.setCreateType(2);
rb.setRound(roomInfoData.getInt("round"));

JSONArray sel1 = roomInfoData.getJSONArray("sel1");
List<Integer> sel = JSONArray.toList(sel1);
Iterator it = sel.iterator();
while(it.hasNext()){  
int num = (int) it.next();
System.out.println(num);

}  

System.out.println(rb.build().getType());


其中关于类型的转换不需要管,只是拿着要做的事情做了一个测试,发现可以获取到值,重要的是能取得集合。

fromObject转换的是json,更换掉之后,下面的set以及类型都不需要管,直接转集合,循环出来就可以了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值