boost::property_tree::json_parser::read_json & Twitter?
I tried real quick as a test to see if I can pipe my twitter feed to boost's JSON parser. No dice. My JSON parser cannot handle the following lines:
"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"
Removing the offending lines gets a populated property tree. Obviously not sufficient fo开发者_C百科r twitter. Here is the code in case I declared my property tree wrong. Help?
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;
}
The answer is to update to the latest version of boost :-). Apparently this library is far from stable. Major changes/refactors in every version.
精彩评论