首页 > 编程语言 > 详细

json数组去重

时间:2017-01-06 13:46:42      阅读:653      评论:0      收藏:0      [点我收藏+]
//名字去重
			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);
			}

  

json数组去重

原文:http://www.cnblogs.com/JAYIT/p/6255852.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!