Dai Chong's blog

jsonString转map

1
JSON.parseObject(string)

实体类转jsonstring

1
JSON.toJSONString(javaClass)

存入redis队列之前是jsonString,拿出来变成object处理办法

1
2
3
4
// 先转字符
String value = lotteryData.index(roomId, userId).toString();
// 转map
JSON.parseObject(value);

如何组成一个多维数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 例子
{
"data": [
{
"nickname": "戴崇",
"userId": 6144,
"roomId": 10086
},
{
"nickname": "戴崇",
"userId": 2174,
"roomId": 10086
},
{
"nickname": "戴崇",
"userId": 9997,
"roomId": 10086
}
],
"code": "0",
"msg": "操作成功!"
}
// 做法
List<Map<String, Object>> list = new ArrayList<>();
for (long userId : rands) {
if (userId == 0) {
continue;
}
String value = lotteryData.index(roomId, userId).toString();
list.add(JSON.parseObject(value));
}

 评论