zoukankan      html  css  js  c++  java
  • 把json对象串转换成map对象

    /** 
      * 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);
       }
      }
     }

  • 相关阅读:
    [leetcode]Combination SumII
    NSum小结
    image 与 canvas 的相互转化
    $_SERVER 相关变量
    最近做的项目,总结一下。
    开始在博客园,写博客,先写点东西。
    Codeforces Round #584 C. Paint the Digits
    Codeforces Round #584 B. Koala and Lights
    Codeforces Round #584 A. Paint the Numbers
    HDU-2296-Ring(AC自动机, DP)
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3050566.html
Copyright © 2011-2022 走看看