如何从 boost 属性 树中读取字段类型
How to read field type from boost property tree
我正在使用 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);
但是我可以读取存储在任何给定字段中的变量类型吗?
[...] 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 解析器,除非您编写自己的代码或添加额外的元数据,否则没有办法。
我正在使用 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);
但是我可以读取存储在任何给定字段中的变量类型吗?
[...] 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 解析器,除非您编写自己的代码或添加额外的元数据,否则没有办法。