搜索
Java Jackson JsonNode 的get(i)方法疑惑
PHP中文网
PHP中文网 2017-04-17 14:52:12
[Java讨论组]
        String str = "{\"data\":{\"birth_day\":7,\"birth_month\":6},\"errcode\":0,\"msg\":\"ok\",\"ret\":0}";

        ObjectMapper mapper = new ObjectMapper();
        JsonNode root = mapper.readTree(str);

        for (int i = 0; i < root.size() ; i++) {
            System.out.println(root.get(i));
        }

        for (Iterator<?> iter = root.fieldNames();iter.hasNext();){
            System.out.println(iter.next());
        }

// null
// null
// null
// null
// data
// errcode
// msg
// ret

为什么前面输出的结果都是Null?

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(1)
迷茫

public JsonNode get(int index)

Method for accessing value of the specified element of an array node. For other nodes, null is always returned.

For array nodes, index specifies exact location within array and allows for efficient iteration over child elements (underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements). If index is less than 0, or equal-or-greater than node.size(), null is returned; no exception is thrown for any index.

参考

http://fasterxml.github.io/jackson-databind/javadoc/2.0.0/

http://fasterxml.github.io/jackson-databind/javadoc/2.0.0/com/fasterxml/jackson/databind/JsonNode.html#get(int)

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号