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
Post a Comment