Created
August 20, 2012 16:36
-
-
Save finalclass/3405616 to your computer and use it in GitHub Desktop.
Simple boost (v1.48) json reading
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 <boost/property_tree/ptree.hpp> | |
#include <boost/property_tree/json_parser.hpp> | |
#include <boost/filesystem.hpp> | |
#include <boost/foreach.hpp> | |
#include <string> | |
#include <set> | |
#include <exception> | |
#include <typeinfo> //for 'typeid' to work | |
int main(int argc, char** argv) { | |
using boost::property_tree::ptree; | |
using boost::property_tree::json_parser::read_json; | |
using std::exception; | |
using std::cout; | |
using std::endl; | |
using std::string; | |
boost::filesystem::path jsonDataFile = boost::filesystem::current_path() / "data.json"; | |
cout << jsonDataFile << endl; | |
try { | |
ptree tree; | |
read_json (jsonDataFile.string(), tree); | |
auto v = tree.get<string>("name"); | |
auto i = tree.get<int>("test"); | |
cout << v << " " << i << endl; | |
} catch(exception &e) { | |
cout << e.what() << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment