JsonVariant::getOrAddMember()
Description
JsonVariant::getOrAddMember() reproduces JsonObject::getOrAddMember(); it only works if the JsonVariant points an object.
-
If the
JsonVariantpoints to an object,JsonVariant::getOrAddMember()gets the value associated with the specified key. If the key is not present in the object, this function adds a new key-value pair to the object. -
If the
JsonVariantdoesn’t point to an object,JsonVariant::getOrAddMember()does nothing.
Instead of this function, you can use JsonVariant::operator[] which offers a more intuitive syntax.
Signatures
JsonVariant getOrAddMember(const char* key) const;
JsonVariant getOrAddMember(const String& key) const;
JsonVariant getOrAddMember(const std::string& key) const;
JsonVariant getOrAddMember(std::string_view key) const;
JsonVariant getOrAddMember(const __FlashStringHelper* key) const;
Arguments
key: the key of the value in the object.
As usual, ArduinoJson makes a copy of the key in the JsonDocument, except if it’s a const char*.
Return value
If the key is already present in the object, this function returns a JsonVariant that points to the associated value.
If the key is not present in the object, this function adds a new key-value pair to the object and returns a JsonVariant that points to the value. The returned JsonVariant could be null if there were not enough room in the JsonDocument.