Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost property tree not able retrive records after parsing json

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 ....`
like image 767
Dhimant Jayswal Avatar asked Nov 29 '12 11:11

Dhimant Jayswal


2 Answers

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.

like image 193
Pedja Avatar answered Nov 15 '22 04:11

Pedja


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.

like image 25
Some programmer dude Avatar answered Nov 15 '22 03:11

Some programmer dude