数据
[
{
"id":"1",
"site_name":[
{
"navi1":"微博热搜",
"navi2":"热门微博"
}
],
"site_icon":"[https://s2.zimgs.cn/ims?kt=url&at=smstruct&key=aHR0cHM6Ly9waWMzNy5waG90b3Bob3RvLmNuLzIwMTUxMDI4LzAwMDUwMTgzMjkwMTE4MDJfYi5qcGc=&sign=yx:TKgi2RqCHVng2jHHHZXMpiaaa5w=&tv=400_400](https://s2.zimgs.cn/ims?kt=url&at=smstruct&key=aHR0cHM6Ly9waWMzNy5waG90b3Bob3RvLmNuLzIwMTUxMDI4LzAwMDUwMTgzMjkwMTE4MDJfYi5qcGc=&sign=yx:TKgi2RqCHVng2jHHHZXMpiaaa5w=&tv=400_400)",
"site_url":"[https://weibo.com/](https://weibo.com/)",
"site_type":"1"
},
{
"id":"2",
"site_name":[
{
"navi1":"虎嗅",
"navi2":"24客卿"
}
],
"site_icon":"[https://h5.sinaimg.cn/m/weibo-lite/img/pwalogo.417d1674.svg](https://h5.sinaimg.cn/m/weibo-lite/img/pwalogo.417d1674.svg)",
"site_url":"[https://m.weibo.cn/?jumpfrom=weibocom](https://m.weibo.cn/?jumpfrom=weibocom)",
"site_type":"1"
},
{
"id":"3",
"site_name":[
],
"site_icon":"[https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png](https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png)",
"site_url":"[https://m.weibo.cn/?jumpfrom=weibocom](https://m.weibo.cn/?jumpfrom=weibocom)",
"site_type":"2"
},
{
"id":"4",
"site_name":[
],
"site_icon":"[https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png](https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png)",
"site_url":"[https://m.weibo.cn/?jumpfrom=weibocom](https://m.weibo.cn/?jumpfrom=weibocom)",
"site_type":"3"
}
]
分组方法
Map<Object, List<Object>> groupBySiteType = siteArr.stream()
.collect(Collectors.groupingBy(item -> JSON.parseObject(item.toString()).get("site_type")));
分组后
{"1": [{"site_name": [{"navi1": "微博热搜","navi2": "热门微博"}],"site_icon": "[https://s2.zimgs.cn/ims?kt=url&at=smstruct&key=aHR0cHM6Ly9waWMzNy5waG90b3Bob3RvLmNuLzIwMTUxMDI4LzAwMDUwMTgzMjkwMTE4MDJfYi5qcGc=&sign=yx:TKgi2RqCHVng2jHHHZXMpiaaa5w=&tv=400_400](https://s2.zimgs.cn/ims?kt=url&at=smstruct&key=aHR0cHM6Ly9waWMzNy5waG90b3Bob3RvLmNuLzIwMTUxMDI4LzAwMDUwMTgzMjkwMTE4MDJfYi5qcGc=&sign=yx:TKgi2RqCHVng2jHHHZXMpiaaa5w=&tv=400_400)","site_url": "[https://weibo.com/](https://weibo.com/)","site_type": "1","id": "1"},{"site_name": [{"navi1": "虎嗅","navi2": "24客卿"}],"site_icon": "[https://h5.sinaimg.cn/m/weibo-lite/img/pwalogo.417d1674.svg](https://h5.sinaimg.cn/m/weibo-lite/img/pwalogo.417d1674.svg)","site_url": "[https://m.weibo.cn/?jumpfrom=weibocom](https://m.weibo.cn/?jumpfrom=weibocom)","site_type": "1","id": "2"}],"2": [{"site_name": [],"site_icon": "[https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png](https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png)","site_url": "[https://m.weibo.cn/?jumpfrom=weibocom](https://m.weibo.cn/?jumpfrom=weibocom)","site_type": "2","id": "3"}],"3": [{"site_name": [],"site_icon": "[https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png](https://h5.sinaimg.cn/m/emoticon/icon/others/d_doge-be7f768d78.png)","site_url": "[https://m.weibo.cn/?jumpfrom=weibocom](https://m.weibo.cn/?jumpfrom=weibocom)","site_type": "3","id": "4"}]}}
为什么?
网上也找了很多的例子,但是大都是遍历或者明确知道JSONArray
里面参数是什么对象类型的,对于这种不知道类型没见到有人记录怎么搞,故此记录,便于后人解惑!