As there is a lot of questions already on this, I am kind of apprehensive about asking... but
I've looked at many different Questions and nothing from any of them is working for me. I have this code as my attempt but it doesn't work:
#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"
using namespace boost::property_tree;
...
std::ifstream jsonFile("test_file.json");
if (!jsonFile){
std::cerr << "Error opening file\n";
return -1;
}
ptree pt;
json_parser::read_json(jsonFile, pt);
for (auto& array_element : pt) {
for (auto& property : array_element.second) {
std::cout << property.first << " = " << property.second.get_value<std::string>() << "\n";
}
}
Its contents are in the following format:
[{"number": 1234,"string": "hello world"}, {"number": 5678,"string": "foo bar"}, ... etc }]
I can't get it to read out the 1234
and then the hello world
. Infact, it just does nothing. How can I read out from my .JSON
file?