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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:32:31  来源:igfitidea点击:

What is the difference between ObjectNode and JsonNode in Hymanson?

javajsonHymansonHymanson2

提问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 ObjectNodeand 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

JsonNodeis a base class that ObjectNodeand ArrayNodeextend. JsonNoderepresents any valid Json structure where as ObjectNodeand ArrayNodeare particular implementations for objects (aka maps) and arrays, respectively.

JsonNode是一个基类,ObjectNodeArrayNode延伸。JsonNode表示任何有效的 Json 结构,其中 asObjectNodeArrayNode分别是对象(又名映射)和数组的特定实现。

ArrayNodehas specific methods for dealing with arrays such as get(index i)E.g. you cannot get an item at a specific index in a JsonNodeor ObjectNodebut you can in an ArrayNode.

ArrayNode有处理阵列具体方法如get(index i)例如你不能在在指定索引得到一个项目JsonNodeObjectNode,但你可以在一个ArrayNode