Search code examples
c++jsonboostboost-propertytree

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 ....`

Solution

  • 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.