#include <ArduinoJson.h>
//Both datatypes work below
String my_array = "[1,2,3,4,5,6,7,8,9,0]";
//const char my_array[40] = "[1,2,3,4,5,6,7,8,9,0]";
int my_int_array[10];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// compute the required size
const size_t CAPACITY = JSON_ARRAY_SIZE(10);
// allocate the memory for the document
StaticJsonDocument<CAPACITY> doc;
// parse a JSON array
deserializeJson(doc, my_array);
// extract the values
JsonArray array = doc.as<JsonArray>();
/*
for(JsonVariant v : array) {
Serial.println(v.as<int>());
}
*/
int i = 0;
for(JsonVariant v : array) {
my_int_array[i] = v.as<int>();
i++;
}
}
void loop() {
for(int j = 0; j < 10; j++) {
Serial.println(my_int_array[j]);
delay(1000); // this speeds up the simulation
}
}