there is a QJsonObject
{
"a":"...",
"b":"...",
"c":"..."
}
is there a method to check if this object contains "a"?
You have a few options, according to the documentation:
QJsonObject::contains
which returns a boolQJsonObject::find
which will return an iterator. If the item isn't found, the return value will be equal to QJsonObject::end
Use this if you need an iterator anyways.QJsonObject::value
, which will return the value for the key if present, and QJsonValue::Undefined
otherwise. You're probably using the value method anyways to get the value for a key, so this will allow you to do one lookup instead of two. It may be tempting to use this for a performance boost, but remember that it will be harder to read and in most cases the performance gain is small enough that it's probably not worth itAll of this came directly from the Qt documentation - my favorite thing about Qt is their fantastic documentation, so I encourage you to make that your first stop when you have questions like these.