JsonObject::getOrAddMember()
Removed in ArduinoJson 6.20: use JsonObject::operator[]
instead.
Description
JsonObject::getOrAddMember()
gets the value associated with the specified key, or creates it if it doesn’t exist.
If the JsonObject
is null, this function does nothing.
Instead of this function, you can use JsonObject::operator[]
which offers a more intuitive syntax.
Signatures
JsonVariant getOrAddMember(char* key) const;
JsonVariant getOrAddMember(const char* key) const;
JsonVariant getOrAddMember(const __FlashStringHelper* key) const;
JsonVariant getOrAddMember(const String& key) const;
JsonVariant getOrAddMember(const std::string& key) const;
JsonVariant getOrAddMember(std::string_view key) const; // 🆕 (added in 6.18.1)
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*
.
String duplication
ArduinoJson makes a copy of the string when you call this function with one of the following types:
char*
String
(orstd::string
)const __FlashStringHelper*
(i.e. Flash string)
This duplication consumes some space in the JsonDocument
; don’t forget to increase its capacity accordingly.
Return value
If the key is already present in the object, this function returns JsonVariant
that points to the associated value.
If the key is not present in the object, this function adds a new value in the object and returns a JsonVariant
that points to this value.