如何在不知道子节点的情况下访问JSON值?

时间:2017-03-06 09:13:38

标签: c++ json boost boost-propertytree

尝试为我的应用程序动态创建JSON,但我收到的JSON不会保持不变。

std::string ResponseJson::getValue(std::string filter, std::string      filterName, std::string jsonIndex)
{
 BOOST_FOREACH(boost::property_tree::ptree::value_type & arrayElement, root.get_child("message"))
{
    std::string value = arrayElement.second.get<std::string>(filter);
    if (value == filterName)
    {
        return arrayElement.second.get<std::string>(jsonIndex);
    }
}
return "";
}

上面的代码段运行良好,但message是可以在不同jsons中更改的子代,那么如何才能使此函数通用?

0 个答案:

没有答案
相关问题