json数组去重

//名字去重
			Map<String,Integer> map=new HashMap<String,Integer>();
			for(int i=0;i<jows.size();i++){
				JSONObject jo = (JSONObject) jows.get(i);
				map.put(jo.get("serviceType").toString(),0);
			}
			for(int i=0;i<jows.size();i++){
				JSONObject jo1 = (JSONObject) jows.get(i);
				if(map.containsKey(jo1.get("serviceType"))){
					map.put(jo1.get("serviceType").toString(),Integer.parseInt(jo1.get("amount").toString())+map.get(jo1.get("serviceType")));
				}
				
			}
			for(Map.Entry<String, Integer> entry : map.entrySet())    
			{    
				JSONObject jo2 =new JSONObject();
				jo2.put("serviceType", entry.getKey());
				jo2.put("amount", entry.getValue());
				jows1.add(jo2);
			}

  

原文地址:https://www.cnblogs.com/JAYIT/p/6255852.html