现在的位置: 首页 > 综合 > 正文

把json对象串转换成map对象

2013年05月26日 ⁄ 综合 ⁄ 共 985字 ⁄ 字号 评论关闭

/** 
  * nc只支持简单的
  * 把json对象串转换成map对象 
  * @param jsonObjStr e.g. {'name':'get','int':1,'double',1.1,'null':null} 
  * @return Map 
  */ 
    public static Map getMapFromJsonObjStr(String jsonObjStr) {  
        JSONObject jsonObject = JSONObject.fromObject(jsonObjStr);  
 
       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 void main(String[] args) {
  //String splitStr = "200$1111 ";
  //System.out.println(getNodeValueString(splitStr, 1, ":"));
  //System.out.println(getNodeValueString(splitStr, 0, ":"));
  String str="{JAVA:{ONEQUERY:dd},FLEX:{JL:[{1:请选择,2:-1}],YMJL:{FIND:ID+MBID,ACTION:RELOADING}} }";
  String jsonObjStr="{$_dataId:'张三,王武',$_actionType:789,YMJL:8}";
  Map map=getMapFromJsonObjStr(jsonObjStr);
  if (map != null) {
   for (Object _key : map.keySet()) {
    Object _value = map.get(_key);
    System.out.println("_key:"+_key+",_value:"+_value);
   }
  }
 }

 

抱歉!评论已关闭.