标签:int json 去重 put log add amount contains class
//名字去重 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); }
标签:int json 去重 put log add amount contains class
原文地址:http://www.cnblogs.com/JAYIT/p/6255852.html