JSON格式数据根据某个属性进行排序(倒序)
[
{
"data": [
{
"name": "一致",
"vlaue": "1"
},
{
"name": "不一致",
"vlaue": "2"
},
{
"name": "不评价",
"vlaue": "2"
},
{
"name": "一致率",
"vlaue": "20"
}
],
"name": "上海",
"id": "1"
},
{
"data": [
{
"name": "一致",
"vlaue": "3"
},
{
"name": "不一致",
"vlaue": "1"
},
{
"name": "不评价",
"vlaue": "1"
},
{
"name": "一致率",
"vlaue": "60"
}
],
"name": "北京",
"id": "2"
}
]
Map<Integer,Object> map = new TreeMap<>(Comparator.reverseOrder());
String json = "";
List<Demo> demos = JsonUtil.toList(json, Demo.class);
for (Demo demo: demos) {
for (Data data: demo.getData()) {
if(data.getName().equals("不一致")){
map.put(Integer.parseInt(data.getVlaue()),demo);
}
}
}
System.out.println(map);
|