I know how to parse "normal" looking JSON data in C++. Usually, I do this, using boost::property_tree and read_json method. It may look like so:
BOOST_FOREAH(ptree::value_type &v, pt.get_child("rows"){
vec.push_back(v.second.get<std::string>("key"));
}
and the code above corresponds to this JSON file:
{
"rows":[{
"key":"1"
},{
"key":"2"
}]
}
However, the Neo4j result-set that I get, looks like:
{
"columns":{...},
"data":[[["object 1"]], [["object 2"]], [["object 3"]]]
}
I'm interested and want to parse "data" node. I tried to do it like so:
BOOST_FOREAH(ptree::value_type &v, pt.get_child("data"){
vec.push_back(v.second.data());
}
but this does not work. I do not get an error, but my vector vec remains empty, or to be more precise it is populated with empty values. So, that when I iterate through this vec I see a number of elements, but they do not have any value. Whereas, I want to have values "object 1", "object 2", "object 3".
arrayshould give you helpful answers in seconds. I would like to conclude with my caveat that Boost doesn't come with a JSON or XML library. It does have a property tree library. People confusing the two are a very frequent occurrence and Stack Overflow is littered with the wreckage of that.