json转换为map


msg 的值为下String类型的json字符串:


{'msgType':'0','opType':'FINGERGAMEINVITE','srcId':'9','srcTele':'18157170715','destTele':'15085831513','stime':'1280977330000','sign':'a7f217174d722a1ee66a88fc5249fe04'}


              Map map = json2Map(msg);//这里实现转换为map实现了标题的功能,没坑你吧     
			 Map sortMap = new TreeMap(map);
		        sortMap = Maps.filterValues(sortMap, new Predicate() {

		            @Override
		            public boolean apply(String input) {
		                return !Strings.isNullOrEmpty(input);
		            }
		        });
		        String keyValPairs = Joiner.on("&").withKeyValueSeparator("=").join(sortMap);
		        keyValPairs = keyValPairs
		        ourSign = DigestUtils.md5Hex(keyValPairs).toLowerCase();
		        MixHelper.print(ourSign);





public static Map json2Map(String json) throws Exception{
	    Map map=new HashMap();  
		org.json.JSONObject jsonObject = new org.json.JSONObject(json);
		Iterator iterator = jsonObject.keys();
		while (iterator.hasNext()) {
			String key = (String)iterator.next();
			String value = jsonObject.get(key).toString();
			if(value.startsWith("{")&&value.endsWith("}")){  
	            map.put(key, json2Map(value));  
	        }else{  
	            	map.put(key, value); 
	        }  
		}
		return map;
	}

你可能感兴趣的:(json)