Reputation: 109
Is it possible to read the following data below using boost?
{
"ok": true,
"result": [
{
"update_id": 1235285,
"message": {
"message_id": 2,
"from": {
"id": 3325446,
"is_bot": false,
"first_name": "Test",
"language_code": "en-PH"
},
"chat": {
"id": 12532541,
"first_name": "Test Account",
"type": "private"
},
"date": 152014521,
"text": "Test Message"
}
}
]
}
Upvotes: 0
Views: 776
Reputation: 47794
You could see the linked post in comment,
To summarize you can have like following to read from a file say mfile.json
:
boost::property_tree::ptree pt;
boost::property_tree::read_json("myfile.json", pt);
print_contents( pt );
where print_contents
is:
void print_contents( const boost::property_tree::ptree& pt)
{
using boost::property_tree::ptree;
for (const auto& x: pt )
{
std::cout << x.first << ": " << x.second.get_value<std::string>() << std::endl;
print_contents(x.second);
}
}
I could have closed it as duplicate, but looks like there was no "better" post for reading a json file
Upvotes: 1