A RetroSearch Logo

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

Search Query:

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

JsonArray::add() | ArduinoJson 6

Description

JsonArray::add() appends a value to the array pointed by the JsonArray.

If the JsonArray is null/unbound, this function does nothing.

Signatures
bool add(bool value) const;

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

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

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

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

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

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

value: the value to add to the array.

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

Return value

JsonArray::add() return a bool that tells whether the operation was successful or not:

User-defined types

JsonArray::add() supports user-defined types by calling convertToJson(). For example, to support tm, you must define:

bool convertToJson(const tm& src, JsonVariant dst) {
  char buf[32];
  strftime(buf, sizeof(buf), "%FT%TZ", &src);
  return dst.set(buf);
}

This feature was added in ArduinoJson 6.18.0, see article for details.

Example
StaticJsonDocument<200> doc;
JsonArray array = doc.to<JsonArray>();
array.add("hello");
array.add(3.14156);
serializeJson(doc, Serial);

will write

See also
  1. Home
  2. Version 6
  3. API
  4. JsonArray
  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