后端打印的日志:
[{"id":30
"shopId":1
"goodsQuantity":1
"goodsPrice":43
"goodsName":"qewrr"
"selected":true
"goodsPicture":"http://localhost:8080/goods/showMyGoodsImg-goodsImg-30"}
{"id":40
"shopId":8
"goodsQuantity":1
"goodsPrice":128.55
"goodsName":"眼镜"
"selected":true
"goodsPicture":"http://localhost:8080/goods/showMyGoodsImg-goodsImg-40"}]
userId:1consigneeName:张三orderPrice:171.55orderNo:201904161657316987993
很简单,我回答要是被删了你就是个刷声望的拖
public static void main(String[] args) {
String json = "[{\"id\":30,\"shopId\":1,orderNo:\"13213132132\"},{\"id\":40,\"shopId\":2,orderNo:\"13213132133\"}," +
"{\"id\":50,\"shopId\":1,orderNo:\"13213132134\"}]";
List<Map<String,Object>> list=(List<Map<String, Object>>) JSONObject.parse(json);
Map<String, List<Map<String,Object>>> newmap=new HashMap<>();
for (Map<String,Object> oldList : list) {
String shopId=String.valueOf(oldList.get("shopId"));
List<Map<String,Object>> m=null;
if(newmap.containsKey(shopId)){
m=newmap.get(shopId);
}else{
m=new ArrayList<>();
}
m.add(oldList);
newmap.put(shopId,m);
}
System.out.println(newmap.toString());
}