• Java用Jackson遍历json所有节点


    <!-- jackson begin -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.1.4</version>
    </dependency>
    <!-- jackson end -->
    
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
        public static void jsonLeaf(JsonNode node)
        {
            if (node.isValueNode())
            {
                System.out.println(node.toString());
                return;
            }
    
            if (node.isObject())
            {
                Iterator<Entry<String, JsonNode>> it = node.fields();
                while (it.hasNext())
                {
                    Entry<String, JsonNode> entry = it.next();
                    jsonLeaf(entry.getValue());
                }
            }
    
            if (node.isArray())
            {
                Iterator<JsonNode> it = node.iterator();
                while (it.hasNext())
                {
                    jsonLeaf(it.next());
                }
            }
        }
        
        public static void main(String[] args)
        {
            try
            {
                String json = FileUtils.readFileToString(new File("C://test.json"), "UTF-8");
                ObjectMapper jackson = new ObjectMapper();
                JsonNode node = jackson.readTree(txt);
                jsonLeaf(node);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    PBI REFRESH ERROR
    PTE
    Python
    Chromedriver下载地址
    python pip安装selenium时报错, ..has requirement websocket-client==0.48.0, but you'll have websocket -client 0.57.0 which is incoopatibale.
    在打开方式里只有wps,找不到默认的MS OFFICE办公PPT打开方式 解决方案
    POWER BI
    POWER BI
    [未解决]POWER BI
    POWER BI 生成日期表
  • 原文地址:https://www.cnblogs.com/witpool/p/8444700.html
Copyright © 2020-2023  润新知