我想解析下面提到的 JSON 并从中提取 productionYear 值
auto data = {
"cars" : [
{
"name" : "BMW",
"engine" : 3.0
},
{
"name" : "Citroen",
"engine" : 3.6
},
{
"name" : "Ferrari",
"engine" : 4.2
}
],
"productionYear" : 1999
}
我有以下规则:
using boost::spirit::ascii::string;
using boost::spirit::omit;
using boost::spirit::qi::lit;
using boost::spirit::qi::char_;
boost::spirit::qi::rule<std::string::iterator, int()> production_;
production_ = omit[*(char_ - "productionYear") >>
lit('"') >> lit(' ') >> lit(':') >> lit(' ')] >> int_;
int year;
auto it = data.begin();
if (boost::spirit::qi::parse(it, data.end(), production_, year))
{
std::cout << "Parse finished with succeded status"
<< std::distance(data.begin(), it);
}
解析器失败,最后一个迭代器位置:0
谁能告诉我我做错了什么?