Created
September 6, 2017 12:18
-
-
Save BraynStorm/002d6ffc4409800b0bb934ead736a61d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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