【发布时间】:2022-01-01 02:35:01
【问题描述】:
使用 Boost C++ 从 JSON ptree 读取值时出现以下错误
Unhandled exception at 0x7682B502 in JSONSampleApp.exe: Microsoft C++ exception :
boost::wrapexcept<boost::property_tree::ptree_bad_path> at memory location 0x00DFEB38.
下面是程序,有人可以帮我看看我在这里缺少什么。
#include <string>
#include <iostream>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>
using namespace std;
using boost::property_tree::ptree;
int main()
{
const char* f_strSetting = "{\"Student\": {\"Name\":\"John\",\"Course\":\"C++\"}}";
boost::property_tree::ptree pt1;
std::istringstream l_issJson(f_strSetting);
boost::property_tree::read_json(l_issJson, pt1);
BOOST_FOREACH(boost::property_tree::ptree::value_type & v, pt1.get_child("Student"))
{
std::string l_strColor;
std::string l_strPattern;
l_strColor = v.second.get <std::string>("Name");
l_strPattern = v.second.get <std::string>("Course");
}
return 0;
}
【问题讨论】:
标签: c++ json boost boost-propertytree