I'm trying to convert an item from an ArduinoJson array to a char, and wondering if someone can help.
My code:
#include <ArduinoJson.h>
DynamicJsonDocument json_doc(10000); // remember to allow enough size!
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Starting up...");
}
void loop() {
long seconds;
float height;
char event_type;
String data = "[[1672049760, \"H\", 4.45, \"12/26/2022 02:16\"], [1672067940, \"L\", 2.71, \"12/26/2022 07:19\"], [1672068415, \"s\", 0.0, \"12/26/2022 07:26\"], [1672079929, \"m\", 3.0, \"12/26/2022 10:38\"], [1672085532, \"N\", 0.0, \"12/26/2022 12:12\"], [1672087740, \"H\", 5.62, \"12/26/2022 12:49\"], [1672098434, \"q\", 3.0, \"12/26/2022 15:47\"], [1672102649, \"S\", 0.0, \"12/26/2022 16:57\"], [1672114440, \"L\", -1.11, \"12/26/2022 20:14\"], [1672117441, \"M\", 4.0, \"12/26/2022 21:04\"], [1672139040, \"H\", 4.52, \"12/27/2022 03:04\"], [1672154836, \"s\", 0.0, \"12/27/2022 07:27\"], [1672158480, \"L\", 2.56, \"12/27/2022 08:28\"]]";
deserializeJson(json_doc, data);
JsonArray array = json_doc.as<JsonArray>();
for(JsonVariant v : array) {
seconds = v[0].as<signed long>();
height = v[2].as<float>();
Serial.println(height);
event_type = v[2].as<signed char>();
Serial.println(event_type);
}
Serial.println("---");
delay(1000);
}
Note this line:
event_type = v[2].as();
I'm pretty sure the issue is that a char doesn't support item assignment, but I can't figure out exactly how to cast the value from the ArduinoJson to my char (the variable "event_type").
I don't imagine anyone has an idea?