gpt4 book ai didi

Jackson JSON JsonNode 和 ObjectNode 的区别

转载 作者:行者123 更新时间:2023-12-02 04:49:00 25 4
gpt4 key购买 nike

我正在使用 Jackson 进行 JSON 解析。JsonNodeObjectNode 有什么区别?

以及用于以字符串格式映射 JSON。

最佳答案

快速回答

  • JsonNode :抽象类,读取 JSON 文档时使用。
  • ObjectNode :具体实现,在构建或修改 JSON 文档时使用。

继续阅读以获得更详细的答案。

JsonNode

JsonNode是一个抽象类,用作所有 JSON 节点的基类,构成 Jackson 实现的 JSON 树模型的基础。

引用JsonNode文档:

As a general design rule, most accessors (getters) methods are included in this base class, to allow for traversing structure without type casts.

Mutators methods (setters), however, need to be accessed through specific sub-classes (such as ObjectNode and ArrayNode).

This seems sensible because proper type information is generally available when building or modifying trees, but less often when reading a tree (newly built from parsed JSON content).

JsonNode具体实现可以参见com.fasterxml.jackson.databind.node包。

对象节点

ObjectNodeJsonNode具体实现映射一个 JSON 对象,JSON 对象是 defined as following :

An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

JSON object

关于Jackson JSON JsonNode 和 ObjectNode 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38759976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com