数据
{ "statuscode": 200, "code": 200, "data": [ { "UserID": 2135605, "ID": 100368, "Keyword": "测试" }, { "UserID": 2135605, "ID": 107520, "Keyword": "万能试验机" }, { "UserID": 2135605, "ID": 108191, "Keyword": "芒果" }, { "UserID": 2135605, "ID": 108625, "Keyword": "塑料瓶" }, { "UserID": 2135605, "ID": 108687, "Keyword": "巨峰蜂蜜" }, { "UserID": 2135605, "ID": 109210, "Keyword": "湖人队提货人团队和" }, { "UserID": 2135605, "ID": "1252638095514402816", "Keyword": "香蕉" }, { "UserID": 2135605, "ID": "1253770116319936512", "Keyword": "苹果" } ], "success": true }
JSONObject object = JSON.parseObject(str); List<JSONObject> objects = object.getJSONArray("data").toJavaList(JSONObject.class); Map<Integer, String> collect = objects.stream().collect(Collectors.groupingBy(o -> o.getInteger("UserID"), Collectors.mapping(o -> o.getString("Keyword"), Collectors.joining(";"))));
结果
{2135605=测试;万能试验机;芒果;塑料瓶;巨峰蜂蜜;湖人队提货人团队和;香蕉;苹果}