A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://arduinojson.org/v6/api/jsondocument/add/ below:

JsonDocument::add() | ArduinoJson 6

Description

When the JsonDocument contains an array, JsonDocument::add() appends a value to the array.

When the JsonDocument contains a value that is not an array, JsonDocument::add() does nothing.

When the JsonDocument is empty, JsonDocument::add() converts the JsonDocument to an array containing one element.

This feature allows creating an array without calling JsonDocument::to<JsonArray(). For example the two following snippets are equivalent:

JsonArray arr = doc.to<JsonArray>();
arr.add(42);
doc.clear();
doc.add(42);
Signatures
bool add(bool value);

bool add(float value);
bool add(double value);

bool add(signed char value);
bool add(signed long value);
bool add(signed int value);
bool add(signed short value);
bool add(unsigned char value);
bool add(unsigned long value);
bool add(unsigned int value);
bool add(unsigned short value);

bool add(char *value);                       // stores a copy
bool add(const char *value);                 // stores a pointer ⚠️
bool add(const __FlashStringHelper *value);  // stores a copy

bool add(const String &value);       // stores a copy
bool add(const std::string &value);  // stores a copy
bool add(const Printable& value);    // stores a copy
bool add(std::string_view value);    // stores a copy

bool add(JsonArray array);          // stores a deep copy
bool add(JsonObject object);        // stores a deep copy
bool add(JsonVariant variant);      // stores a deep copy
bool add(const JsonDocument& doc);  // stores a deep copy

bool add(TEnum value);  // alias of add(int)
bool add(T value);      // calls user-defined function
Arguments

value: the value of to append to the array, it can be any type supported by ArduinoJson.

All types are stored by copy, except const char* which is stored by pointer.

Return value

JsonDocument::add() returns a bool that tells whether the operation was successful or not:

Example
StaticJsonDocument<200> doc;
array.add("hello"); // null -> ["hello"]
array.add(3.14156); // ["hello"] -> ["hello",3.14156]
serializeJson(doc, Serial);

will write

See also
  1. Home
  2. Version 6
  3. API
  4. JsonDocument
  5. add()

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4