我试着快速测试一下,看看我是否可以将我的twitter feed传递给boost的JSON解析器。没有骰子。我的JSON解析器无法处理以下行:
"profile_background_image_url":"http:\/\/a2.twimg.com\/profile_background_images\/4531792\/wallpaper_stock.jpg",
"url":"http:\/\/on.fb.me\/bShBVQ",
exception error: "invalid escape sequence"
"id":86162751646482432,
exception error: "expected value"
删除有问题的行会获得一个填充的属性树。对于Twitter来说显然不够。这是代码,以防我声明我的属性树错误。帮助
int main (int argc, char * const argv[])
{
boost::property_tree::basic_ptree<std::string,std::string> pt;
std::ifstream f;
f.open("testJSON2a.txt");
if(!f.is_open())
{
std::cout << "Error";
return 0;
}
try
{
boost::property_tree::json_parser::read_json(f,pt);
boost::property_tree::basic_ptree<std::string,std::string>::const_iterator iter = pt.begin(),iterEnd = pt.end();
for(;iter != iterEnd;++iter)
{
std::cout << iter->first << " " << iter->second.get_value<std::string>() << std::endl;
}
}
catch(boost::property_tree::json_parser::json_parser_error &je)
{
std::cout << "Error parsing: " << je.filename() << " on line: " << je.line() << std::endl;
std::cout << je.message() << std::endl;
}
return 0;
}
答案 0 :(得分:2)
答案是更新到最新版本的boost :-)。显然这个图书馆远非稳定。每个版本中的主要更改/重构。