c++ - Testing if boost property tree stores a primitive or a subtree -


i'm parsing json file in value corresponding key can primitive (string) or subtree. useful example storing information people single employer, example

{     "employer" : "nasa"; } 

or people multiple employers, example

{     "employer" :     {         "weekdays" : "taco bell" ,         "weekends" : "google inc"     } } 

while parsing employer key need test whether property tree value stores primitive (single employer) or subtree (multiple employers). i've tried get_value_optional shown below, still initialized employername that's empty string. there way go this.

boost::optional<std::string> employername = propertytree.get_value_optional<std::string>(); if( employername.is_initialized() ) {     std::string name = employername.get(); // returns empty string if propertytree stores subtree } 

found answer: propertytree.size().


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -