gpt4 book ai didi

c++ - Boost ptree 顶级数组

转载 作者:行者123 更新时间:2023-11-30 02:28:51 27 4
gpt4 key购买 nike

我想让 write_json 输出一个顶级数组,效果如下:

[{...},{...},{...},...,{...}]

但是当我将列表传递给 write_json 时,它会转换为充满空白键的 json。

{"":{...},"":{...},"":{...},..."":{...}}

使用 add_child 实际上尊重数组并给了我最接近的东西:

{"Some Key":[{...},{...},{...},...,{...}]}

但这仍然不是我想要的。

知道如何使该数组成为顶级吗?

最佳答案

Boost 没有 JSON 库(也没有 XML 库)。它有一个 Property Tree 库(恰好包含一个 JSON 兼容的表示)。

您遇到的限制非常清楚地记录在案:http://www.boost.org/doc/libs/1_62_0/doc/html/property_tree/parsers.html#property_tree.parsers.json_parser

The property tree dataset is not typed, and does not support arrays as such. Thus, the following JSON / property tree mapping is used:

  • JSON objects are mapped to nodes. Each property is a child node.
  • JSON arrays are mapped to nodes. Each element is a child node with an empty name. If a node has both named and unnamed child nodes, it cannot be mapped to a JSON representation.
  • JSON values are mapped to nodes containing the value. However, all type information is lost; numbers, as well as the literals "null", "true" and "false" are simply mapped to their string form.
  • Property tree nodes containing both child nodes and data cannot be mapped.
  • JSON round-trips, except for the type information loss.

它继续显示您遇到的确切示例。

关于c++ - Boost ptree 顶级数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40292925/

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