{
"condition": [
{
"condName": "name1",
"condValue": [
"val11",
"val12"
]
},
{
"condName": "name2",
"condValue": [
"val21"
]
},
{
"condName": "name3",
"condValue": [
"val31",
"val32",
"val33"
]
}
],
"total": 3
}
@Data
public class Request {
private List<Condition> condition;
private Long total;
}
@Data
public class Condition {
private String condName;
private List<String> condValue;
}
转换方法(读取 json 和转成 Request 对象的代码省略。。。):
String json = getContent();
try {
List<Condition> conditions = deseriliaze(json).getCondition();
Map<String, List<Condition>> map1 = conditions.stream().collect(Collectors.groupingBy(Condition::getCondName));
Map<String, List<List<String>>> map2 = conditions.stream().collect(Collectors.groupingBy(Condition::getCondName, Collectors.mapping(Condition::getCondValue, Collectors.toList())));
} catch (Exception e) {
e.printStackTrace();
}
{name3=[Condition(condName=name3, condValue=[val31, val32, val33])], name2=[Condition(condName=name2, condValue=[val21])], name1=[Condition(condName=name1, condValue=[val11, val12])]}
{name3=[[val31, val32, val33]], name2=[[val21]], name1=[[val11, val12]]}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.