java ConvertJsonToMap

 public static Map<String, Object> jsonToMap(Stack<JSONObject> stObj, Map<String, Object> resultMap){
        try {
            if (stObj == null && stObj.pop() == null) {
                return null;
            }
            JSONObject json = stObj.pop();
            Iterator it = json.keys();
            while (it.hasNext()) {
                String key = (String) it.next();
                //得到value的值
                Object value = json.get(key);
                if (value instanceof JSONObject) {
                    stObj.push((JSONObject) value);
                    //递归遍历
                    jsonToMap(stObj, resultMap);
                } else {
                    resultMap.put(key, value);
                }
            }
        } catch (JSONException e) {
            throw new RuntimeException("json格式错误,请核查!");
        }
        return resultMap;
    }

你可能感兴趣的:(java,util)