c++ - 如果键名带有点(.),则在 C++ 中使用 ptree 从 json 中获取值

标签 c++ json boost-propertytree

我尝试使用 ptree 在 C++ 中获取键值,因为键名有多个 .在键中。

所以我有 json,

"product": {
    "product.description.text": "Some text here"
}

我试过打电话

std::string product = pt.get_value("product.product.description.text");

但是取不到值。 请帮助我

最佳答案

根据 http://www.boost.org/doc/libs/1_43_0/doc/html/boost_propertytree/accessing.html 您可以使用如下内容:

pt.get<std::string>('/', "product/product.description.text");

关于c++ - 如果键名带有点(.),则在 C++ 中使用 ptree 从 json 中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31340974/

相关文章:

c++ - 从 URL 下载 Qt 中的文件

c++ - 在 Qstring 中插入一个整数变量作为参数并将其发送到 Serial.write

c++ - ofstream(mode ios::out) 在系统停止时删除现有文件空白

c++ - 如何使用 C++ 将 Boost ptree 插入 MongoDB

c++ - 如何使 char 数组与输入的大小相同(或者可以使用字符串库而不是 C 样式数组字符串来完成)?

php - PHP 中的 MySQL 数据按日期时间对 JSON 数据进行排序

json - 如何使用 SwiftyJSON 解析这种 JSON API

json - 操纵mongodb的bson.D输出格式

c++ - 从 boost::property_tree::ptree::iterator 获取 ptree

c++ -/usr/bin/ld : warning: abc. 所以,找不到 xyz.so 所需(尝试使用 -rpath 或 -rpath-link)”