I have a json that looks like this:
{"field":{"val1":25, "val2":48, "name1":"qqd"}}
When I do a verification of the received json has the specific fields like this:
std::size_t fcnt = pt.count("field");
std::size_t val1cnt = pt.count("field.val1");
std::size_t val2cnt = pt.count("field.val2");
std::size_t nm1cnt = pt.count("field.name1");
std::cout << fcnt << val1cnt << val2cnt << nm1cnt << std::endl; // this is just for testing
if (fcnt != 1 || val1cnt != 1 || val2cnt != 1 || nm1cnt !=1)
throw BadJSONFormatException();
I get always the exception and the values printed are: 1000
. Why? count
does not work like this?
The docs says: "Count the number of direct children with the given key."
In other words, the string you pass is a simple key, not a path. Dots won't get special handling.
I think letting ptree have the dual container/path interface is the largest problem it has. I see so much confusion over it. Something to consider for the next version.