I have the following array of anonymous JSON data and used boost property tree to read the data. I am able to read the data and wondering if there is any better to parse the data using boost property tree.
Here is the data set
[{"id": "1","timestamp": 1509493641,"heartrate": 72},
{"id": "2","timestamp": 1509493642,"heartrate": 74}]
Here is the I code to extract the data and it works.
// boost library headers
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/algorithm/string/erase.hpp>
int main()
{
// Short alias for this namespace
namespace pt = boost::property_tree;
// read the JSON array data using boost property tree
pt::ptree jsonData;
// Load the json file in this ptree
pt::read_json(inputFile, jsonData);
for(auto v = jsonData.begin(); v != jsonData.end(); ++v)
{
const std::string id = v->second.get_child("id").get_value<std::string>();
const int heartrate= v->second.get_child("heartrate").get_value<int>();
}
return 0;
}
Is there any other better way to do this using boost proprty tree library?