A RetroSearch Logo

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

Search Query:

Showing content from https://arduinojson.org/v6/api/misc/copyarray/ below:

copyArray() | ArduinoJson 6

Description

copyArray() copies values between a JsonArray (or JsonDocument) and a regular C array.

It works in both directions:

It supports both 1D and 2D arrays.

Support for JsonDocument was added in ArduinoJson 6.15.2

Signatures
// In the following lines T can be any type supported by JsonVariant
// (for example: bool, int, float, or const char*).
// N, N1, and N2 are integer constants.

// 1D array -> JsonArray/JsonDocument
bool copyArray(T[N] src, JsonArray dst);
bool copyArray(T[N] src, JsonDocument& dst);

// 1D array -> JsonArray/JsonDocument
bool copyArray(T* src, size_t len, JsonArray dst);
bool copyArray(T* src, size_t len, JsonDocument& dst);

// 2D array -> JsonArray/JsonDocument
bool copyArray(T[N1][N2] src, JsonArray dst);
bool copyArray(T[N1][N2] src, JsonDocument& dst);

// JsonArray/JsonDocument -> 1D array
size_t copyArray(JsonArrayConst src, T[N] dst);
size_t copyArray(const JsonDocument& src, T[N] dst);

// JsonArray/JsonDocument -> 1D array
size_t copyArray(JsonArrayConst src, T* dst, size_t len);
size_t copyArray(const JsonDocument& src, T* dst, size_t len);

// JsonArray -> 2D array
void copyArray(JsonArrayConst src, T[N1][N2] dst);
void copyArray(const JsonDocument& src, T[N1][N2] dst);

// these function also support JsonDocument
Return value

Some overloads of copyArray() return a bool that tells whether the copy was successful.

Some overloads of copyArray() return a size_t that contains the number of elements copied.

Example 1D array
int values[] = {1,2,3};

StaticJsonDocument<256> doc;
copyArray(values, doc);
serializeJson(doc, Serial);

will write the following string to the serial port:

2D array
int values[][3] = {{1, 2, 3}, {4, 5, 6}};

StaticJsonDocument<256> doc;
copyArray(values, doc);
serializeJson(doc, Serial);

will write the following string to the serial port:

  1. Home
  2. Version 6
  3. API
  4. copyArray()

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