c++ - boost property tree cannot read multiple json data in one file -
i need decide problem. using boost property tree parse twitter messages stored in json file. messages saved in 1 json file , need parse 1 one.
here twitter json data saved in file. has 3 different messages. (below deducted message test)
{"id":593393012970926082,"in_reply_to_status_id":1,"user":{"id":2292380240,"followers_count":2},"retweet_count":0} {"id":654878454684687878,"in_reply_to_status_id":7,"user":{"id":2292380241,"followers_count":4},"retweet_count":5} {"id":123487894154878414,"in_reply_to_status_id":343,"user":{"id":2292380242,"followers_count":773},"retweet_count":654}
and here c++ code parsing message, using property tree.
#include <boost/property_tree/json_parser.hpp> using namespace std; using namespace boost::property_tree; string jsonfile = "./twitter.json"; int main() { ptree pt; read_json( jsonfile, pt ); cout<<"in_reply_to_status_id: "<<pt.get("in_reply_to_status_id",0)<<"\n"; }
i want in_reply_to_status_id values file. printing first line value. result printing follow.
in_reply_to_status_id: 1
i values below.
in_reply_to_status_id: 1
in_reply_to_status_id: 7
in_reply_to_status_id: 343
how can values file. please me. thank much.
you should have right json file, example this
[ {"id":593393012970926082,"in_reply_to_status_id":1,"user":{"id":2292380240,"followers_count":2},"retweet_count":0}, {"id":654878454684687878,"in_reply_to_status_id":7,"user":{"id":2292380241,"followers_count":4},"retweet_count":5}, {"id":123487894154878414,"in_reply_to_status_id":343,"user":{"id":2292380242,"followers_count":773},"retweet_count":654} ]
and code should this
for (const auto& p : pt) { cout << p.second.get("in_reply_to_status_id",0) << endl; }
instead of range-based for
, can use boost_foreach
example.
boost_foreach(const ptree::value_type& p, pt)
Comments
Post a Comment