gpt4 book ai didi

c++ - 如何从 boost 属性树中读取字段类型

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:51:05 25 4
gpt4 key购买 nike

我正在使用 boost 属性树从 json 文件中读取值。

{
"some_values":
{
"field_1": "value_1",
"field_2": true
}
}

我可以读取值:

spTree->get<string>("some_values.field_1",  "");
spTree->get<bool>("some_values.field_2", false);

但是我可以读取存储在任何给定字段中的变量类型吗?

最佳答案

Documentation says

[...] the following JSON / property tree mapping is used:

[...] 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 解析器,除非您编写自己的代码或添加额外的元数据,否则没有办法。

关于c++ - 如何从 boost 属性树中读取字段类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41931919/

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