JsonVariant::set()
⚠️ Subject to change
Version 6 is currently in beta, so the APIUnless you need the new features of version 6 (e.g. MessagePack), please use version 5.13.4.
Version 6 should stay in beta stage until march 2019.
Description
JsonVariant::set()
replaces the value stored in the variant. The variant may change its type if necessary.
Instead of this function, use JsonArray::operator[]
or JsonObject::operator[]
because they offer a more intuitive syntax
Despite what the name suggests, JsonVariant::set()
is not the reverse operator of JsonVariant::get()
.
Signatures
bool set(bool value) const;
bool set(float value) const;
bool set(double value) const;
bool set(signed char value) const;
bool set(signed long value) const;
bool set(signed int value) const;
bool set(signed short value) const;
bool set(unsigned char value) const;
bool set(unsigned long value) const;
bool set(unsigned int value) const;
bool set(unsigned short value) const;
bool set(char *value) const;
bool set(const char *value) const;
bool set(const __FlashStringHelper *value) const;
bool set(const String &value) const;
bool set(const std::string &value) const;
bool set(JsonArray array) const;
bool set(JsonObject object) const;
bool set(JsonVariant variant) const;
Arguments
value
: the new value of the variant, it can be any type supported by ArduinoJson.
If you pass a JsonArray
, a JsonObject
, or a JsonVariant
, JsonVariant::set()
makes a complete clone of the argument. In other words, the value is stored by copy, not by reference.
As usual, ArduinoJson makes a copy of a string in the JsonDocument
, except if it’s a const char*
.
Return value
JsonVariant::set()
returns a bool
that tells whether the operation was successful or not:
true
if the value operation was successful.false
if there was not enough room in theJsonDocument
.
Remarks
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.