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); }
作者: lost blog
出处: http://www.cnblogs.com/JAYIT/
关于作者:专注服务器端开发
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接 如有问题, 可邮件(sawyershaw@qq.com)咨询.