【发布时间】:2021-02-28 05:31:40
【问题描述】:
我有这个输出 JSON。它来自这种类型
List<List<TextValue>>
TextValue类是String文本,String值。
"data": [
[
{
"text": "DescCode",
"value": "01"
},
{
"text": "DescName",
"value": "Description 1"
},
{
"text": "SecondCode",
"value": "01"
}
],
[
{
"text": "DescCode",
"value": "02"
},
{
"text": "DescName",
"value": "Description 2"
},
{
"text": "SecondCode",
"value": "02"
}
]
]
我想把它转换成这个 JSON。
我相信这就是这个对象设置。
List<Map<String, String>>
"data": [
{
"DescCode": "01",
"DescName": "Description 1",
"SecondCode": "01"
},
{
"DescCode":"02",
"DescName":"Description 2",
"SecondCode":"02"
}
]
我的 JSON 是由我的 Spring REST 控制器自动创建的,所以我真的只需要 Java 对象,Json 仅供参考。
我不知道这个吗? List<Map<String, String>>
【问题讨论】:
-
您好,您可以使用流
map方法将内部List转换为Map。或者,如果从 JSON 解析 custom deserializer 可能会有所帮助
标签: java dictionary java-stream