JsonArray::remove()
Description
Removes the element at the specified index.
Signature
void remove(size_t index);
Arguments
index
: the zero-based position of the element in the array.
Example
JsonArray& array = jsonBuffer.createArray();
array.add("A");
array.add("B");
array.add("C");
array.remove(1);
array.printTo(Serial);
will print the following string to the serial output:
["A","C"]
Causes memory leaks
This function doesn’t free the memory allocated to the element in the
JsonBuffer
.This is a conscious design decision made to keep the
JsonBuffer
fast and small, which is a fundamental principle of the library.As a consequence, you cannot remove and add elements in a loop, otherwise the
JsonBuffer
will overflow.Don’t try to keep the state of your application in a
JsonArray
, instead use custom structures.