Description

Populates the JsonArray with values from a C array.

Signatures

// 1D arrays
JsonArray::copyFrom(T array[len]);
JsonArray::copyFrom(T* array, size_t len);

// 2D arrays
JsonArray::copyFrom(T array[][]);

Arguments

array: an array of value of type T.

len: the number of elements in the array.

T: the type of the value, can be any type supported by ArduinoJson.

Return value

true if the operation is successful; or false if there was not enough room in the JsonDocument.

Example

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

StaticJsonDocument<200> doc;
JsonArray array = doc.to<JsonArray>();
array.copyFrom(values);
serializeJson(array, Serial);

will write

[1,2,3]

See also