Forked from mloskot/boost_property_tree_json_array.cpp
Created
April 22, 2013 17:07
-
-
Save zhuangh/5436771 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#ifdef _MSC_VER | |
#include <boost/config/compiler/visualc.hpp> | |
#endif | |
#include <boost/property_tree/ptree.hpp> | |
#include <boost/property_tree/json_parser.hpp> | |
#include <boost/foreach.hpp> | |
#include <cassert> | |
#include <exception> | |
#include <iostream> | |
#include <sstream> | |
#include <string> | |
int main() | |
{ | |
try | |
{ | |
std::stringstream ss; | |
ss << "{ \"root\": { \"values\": [1, 2, 3, 4, 5 ] } }"; | |
boost::property_tree::ptree pt; | |
boost::property_tree::read_json(ss, pt); | |
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("root.values")) | |
{ | |
assert(v.first.empty()); // array elements have no names | |
std::cout << v.second.data() << std::endl; | |
} | |
return EXIT_SUCCESS; | |
} | |
catch (std::exception const& e) | |
{ | |
std::cerr << e.what() << std::endl; | |
} | |
return EXIT_FAILURE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment