zoukankan      html  css  js  c++  java
  • json转换成list map集合

    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Set;
    
    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    
    public class JSONHelper {
    
        /**
         * 将JSONObjec对象转换成Map集合
         * @see JSONHelper#reflect(JSONArray)
         * @param json
         * @return
         */
        public static HashMap<String, Object> reflect(JSONObject json){
            HashMap<String, Object> map = new HashMap<String, Object>();
            Set keys = json.keySet();
            for(Object key : keys){
                Object o = json.get(key);
                if(o instanceof JSONArray)
                    map.put((String) key, reflect((JSONArray) o));
                else if(o instanceof JSONObject)
                    map.put((String) key, reflect((JSONObject) o));
                else
                    map.put((String) key, o);
            }
            return map;
        }
    
        /**
         * 将JSONArray对象转换成List集合
         * @see JSONHelper#reflect(JSONObject)
         * @param json
         * @return
         */
        public static Object reflect(JSONArray json){
            List<Object> list = new ArrayList<Object>();
            for(Object o : json){
                if(o instanceof JSONArray)
                    list.add(reflect((JSONArray) o));
                else if(o instanceof JSONObject)
                    list.add(reflect((JSONObject) o));
                else
                    list.add(o);
            }
            return list;
        }
    }
  • 相关阅读:
    SHELL脚本自动备份Linux系统
    Linux Shell脚本之自动修改IP
    oracle redo日志维护
    Linux运维工程师面试
    angular 的杂碎报错小知识
    angular.run 妙用
    vue的生命周期
    angular +H5 上传图片 与预览图片
    跨域问题解决方案之chrome插件
    js递归
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5130845.html
Copyright © 2011-2022 走看看