Skip to content

Instantly share code, notes, and snippets.

@BraynStorm
Created September 6, 2017 12:18
Show Gist options
  • Save BraynStorm/002d6ffc4409800b0bb934ead736a61d to your computer and use it in GitHub Desktop.
Save BraynStorm/002d6ffc4409800b0bb934ead736a61d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
using boost::property_tree::ptree;
using boost::property_tree::read_json;
using namespace std;
void load(ptree& json){
ifstream jsonFile("file.json");
cout << "Parsing" << endl;
read_json(jsonFile, json);
jsonFile.close();
}
int main() {
ptree json;
load(json);
auto child_object = json.get_child("worlds");
BOOST_FOREACH(ptree::value_type & child_pair, child_object) {
cout << child_pair.second.get<string>("name") << ", "
<< child_pair.second.get<int>("capacity") << ", "
<< child_pair.second.get<int>("current") << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment