方法记录(一)

public static Map getMapFromJson(String jsonString) {  

        JSONObject jsonObject = JSONObject.fromObject(jsonString);  
        Map map = new HashMap();  
        for(Iterator iter = jsonObject.keys(); iter.hasNext();){  
            String key = (String)iter.next();  
            map.put(key, jsonObject.get(key));  
        }  
        return map;  
    }  
public static Map getMap(Object json) throws Exception{
		
		JSONArray jsonArray = JSONArray.fromObject(json); 
   	   String jsonstr=jsonArray.toString();
   	   if(jsonstr.indexOf("[")>-1&&jsonstr.indexOf("]")>-1){
   	   jsonstr=jsonstr.replace("[","").replace("]","");
   	   }
   	   Map map=getMapFromJson(jsonstr);
	   return map;
	}

Iterator it = map.entrySet().iterator();
			 while(it.hasNext()){
				 Map.Entry entry = (Map.Entry) it.next(); 
				 System.out.println("----Key----->"+entry.getKey()+"=====value=======>"+ entry.getValue());
			 }


你可能感兴趣的:(方法)