For example in a simple json
{
"A" :
{
"B" :
{
--something--
}
}
}
json::Value root;
const Json::Value x = root["A"]["B"];
if (root.isMember("A")) --- always returns TRUE..
Json::Value root;
If (root.isMember("A")) ---- works fine
const Json::Value x = root["A"]["B"];
Any idea what's wrong with First Case? even if I get x
before isMember()
call.
Take a look at documentation.
Value & operator[] (const char *key)
Access an object value by name, create a null member if it does not exist.
const Value & operator[] (const char *key) const
Access an object value by name, returns null if there is no member with that name.
Value & operator[] (const std::string &key)
Access an object value by name, create a null member if it does not exist.
const Value & operator[] (const std::string &key) const
Access an object value by name, returns null if there is no member with that name.
Basically, you are creating the member "A"
on root["A"]
call. To avoid this always check isMember
before actually accessing the member (or call it only on const
object and do a null check instead - I'd preffer the former).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With