Reputation: 123
I have a sample json record that I have parsed via boost json parser and saved it to boost property tree to get all key value pairs.ia following code I am able to get first attribute of tree but how can I get second attributes value ? when I try to get it ,it shows me exception that "No such node".
if I iterate the tree ,then it is showing me all keys.I don't understand whats wrong with it. ref : http://www.boost.org/doc/libs/1_52_0/doc/html/boost_propertytree/accessing.html
json string := {"type":"net.aggregate","post.source":"1209010340", "val":1000}
Code:
boost::property_tree::ptree pt;
read_json("jSon string object", pt);
cout << pt.get("type", ""); // working
cout << pt.get("post.source", "") // showing error ....`
Upvotes: 5
Views: 2123
Reputation: 186
Since the property name contains a dot, you have to use a different separator, so in your case that would be:
cout << pt.get(ptree::path_type("post.source", '/'), "");
Boost documentation section that explains it.
Upvotes: 7
Reputation: 409216
Because Boost property_tree
uses the dot to separate different objects. When you request "post.source"
the get
function looks for an object post
with a property source
.
Upvotes: 1