Java Jackson 中的 ObjectNode 和 JsonNode 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38705890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between ObjectNode and JsonNode in Hymanson?
提问by THIS USER NEEDS HELP
According to the documetation of JsonNode
:
根据文档JsonNode
:
Most mutators, however, need to be accessed through specific sub-classes (such as
ObjectNode
and ArrayNode).
然而,大多数 mutator 需要通过特定的子类(例如
ObjectNode
和 ArrayNode)来访问。
However I am still confused since some stackoverflow answers seem to use them quite interchangeably. What different purpose do they serve?
但是我仍然很困惑,因为一些 stackoverflow 答案似乎可以互换使用它们。它们有什么不同的目的?
采纳答案by bhspencer
JsonNode
is a base class that ObjectNode
and ArrayNode
extend. JsonNode
represents any valid Json structure where as ObjectNode
and ArrayNode
are particular implementations for objects (aka maps) and arrays, respectively.
JsonNode
是一个基类,ObjectNode
和ArrayNode
延伸。JsonNode
表示任何有效的 Json 结构,其中 asObjectNode
和ArrayNode
分别是对象(又名映射)和数组的特定实现。
ArrayNode
has specific methods for dealing with arrays such as get(index i)
E.g. you cannot get an item at a specific index in a JsonNode
or ObjectNode
but you can in an ArrayNode
.
ArrayNode
有处理阵列具体方法如get(index i)
例如你不能在在指定索引得到一个项目JsonNode
或ObjectNode
,但你可以在一个ArrayNode
。