I've been trying the past 2 days to find out how do I do the following thing in C++:
I have a json string:
[
{
"pid" : 0,
"nick":"Foo",
"score":12,
"ping":50
},
{
"pid":1,
"nick":"Bar",
"score":23,
"ping":24
}
]
I want to iterate over all these childs and put, for example, PlayerID's values in a std::vector
so that I can return all of them.
Where I'm stuck is here:
// some code
boost::property_tree::ptree pt;
boost::property_tree::read_json(ss, pt);
std::vector<int> players;
int pid;
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("pid")) // I also tried with pt or pt.get_child("")
{
pid = v.second.data();
players.push_back(pid);
}
return players;
I looked at the documentation but couldn't find anything good. Also, I've tried almost everything there and if it compiles without errors it'd give me what() expected object or something like that. I'm really stuck, any help is appreciated! Thanks in advance.