zoukankan      html  css  js  c++  java
  • 递归获取jsonObject的所有value

     //递归获取jsonObject的所有value
     private StringBuffer mStringBuffer = new StringBuffer();
     public  String getAllContentFromJson(Object cObject) {
    
            if(cObject instanceof JSONObject) {
                JSONObject jsonObject = (JSONObject) cObject;
                for (Map.Entry<String, Object> entry: jsonObject.entrySet()) {
                    Object o = entry.getValue();
                    if(o instanceof Integer){
                        log.info("key:" + entry.getKey() + ",value:" + entry.getValue());
                        mStringBuffer.append(" "+entry.getValue());
                    }else if(o instanceof Double){
                        log.info("key:" + entry.getKey() + ",value:" + entry.getValue());
                        mStringBuffer.append(" "+entry.getValue());
                    }else if(o instanceof Float){
                        log.info("key:" + entry.getKey() + ",value:" + entry.getValue());
                        mStringBuffer.append(" "+entry.getValue());
                    }else if(o instanceof Byte){
                        log.info("key:" + entry.getKey() + ",value:" + entry.getValue());
                        mStringBuffer.append(" "+entry.getValue());
                    }else if(o instanceof Long){
                        log.info("key:" + entry.getKey() + ",value:" + entry.getValue());
                        mStringBuffer.append(" "+entry.getValue());
                    }else if(o instanceof String) {
                        Object object = null;
                        try{
                            object=JSONObject.parseObject((String)o);
                            getAllContentFromJson(object);
                        }catch (Exception e){
                            log.info("key:" + entry.getKey() + ",value:" + entry.getValue());
                            mStringBuffer.append(" "+entry.getValue());
                        }
    
    
                    }
                    else {
                        getAllContentFromJson(o);
                    }
                }
            }
            if(cObject instanceof JSONArray) {
                JSONArray jsonArray = (JSONArray) cObject;
                for(int i = 0; i < jsonArray.size(); i ++) {
                    getAllContentFromJson(jsonArray.get(i));
                }
            }
            return mStringBuffer.toString();
        }
  • 相关阅读:
    C#基础知识汇总(不断更新中)
    比较两个DataTable是否相等
    C#利用SerialPort控件进行串口编程小记
    C# ListBox 自动滚动到底部 方法:
    IIS配置文件的XML格式不正确 applicationHost.config崩溃 恢复解决办法
    net4log 添加自定义变量
    net4log 日志管理
    C#实现加简单的Http请求
    H5,Css小姐又作画了
    H5 ,Css实现了你的logo
  • 原文地址:https://www.cnblogs.com/heyt/p/13574334.html
Copyright © 2011-2022 走看看