Hi everybody,
I have a problem changing the value of a nested key inside a json. I couldn't change the mentioned value as below:
{
"Switches": [
{
"Name": "Room Ligth",
"state": true
}
],
"Sensors": [
{
"Name": "Home Temperature",
"value": 423 // << this value--------------
}
]
}
what Im looking for is something like this:
root["Sensors"][0]["value"]=423;
but when I write the above line my "Weoms mini D1" crashes and restarts.
huge thanks for any ideas
hamed
J-M-L
2
can you try this code:
#include <ArduinoJson.h>
char jsonTxt[] = "{\"Switches\": [{\"Name\": \"Room Ligth\",\"state\": true}],\"Sensors\": [{\"Name\": \"Home Temperature\",\"value\": 423}]}";
void setup() {
DynamicJsonDocument doc(200);
Serial.begin(115200);
deserializeJson(doc, jsonTxt);
long value = doc["Sensors"][0]["value"];
Serial.print(F("Initial Value = ")); Serial.println(value);
doc["Sensors"][0]["value"] = 42;
value = doc["Sensors"][0]["value"];
Serial.print(F("After modification, Value = ")); Serial.println(value);
}
void loop() {}
if all goes well, Serial Monitor (@ 115200 bauds) will show
Initial Value = 423
After modification, Value = 42
system
Closed
4
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.