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

Get value from json using ptree in c++ if key name is with dots(.)

本文关键字:ptree 获取 json c++ 如果      更新时间:2023-10-16

我尝试使用ptree在c++中获取具有多个键名的键值。在钥匙。

我有json,

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

I tried calling

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");