`
tanglong8848
  • 浏览: 67332 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

方法记录(一)

 
阅读更多
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());
			 }


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics