File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -140,13 +140,14 @@ void handleApiRequest() {
140
140
*/
141
141
142
142
const size_t bufferSize = JSON_OBJECT_SIZE (3 ) + JSON_OBJECT_SIZE (4 ) + 70 ;
143
- DynamicJsonBuffer jsonBuffer (bufferSize);
144
- JsonObject& root = jsonBuffer. parseObject ( server.arg (" plain" ));
143
+ DynamicJsonDocument jsonDocument (bufferSize);
144
+ deserializeJson (jsonDocument, server.arg (" plain" ));
145
145
146
146
Serial.println (" JSON Body: " );
147
- root. printTo ( Serial);
147
+ serializeJson (jsonDocument, Serial);
148
148
Serial.println ();
149
149
150
+ JsonObject root = jsonDocument.as <JsonObject>();
150
151
const char * state = root[" state" ]; // "ON" or "OFF"
151
152
if (strcmp (" OFF" , state) == 0 ) {
152
153
Serial.println (" State OFF found: switching off" );
@@ -165,12 +166,12 @@ void handleApiRequest() {
165
166
166
167
// DEBUG: color
167
168
Serial.print (" Color: " );
168
- root[" color" ]. printTo ( Serial);
169
+ serializeJson ( root[" color" ], Serial);
169
170
Serial.println ();
170
171
171
172
RGB rgb = {0 , 0 , 0 };
172
- JsonObject& color = root[" color" ];
173
173
174
+ JsonObject color = root[" color" ];
174
175
// If RGB mode: Parse RGB values
175
176
if (color[" mode" ] == " rgb" ) {
176
177
// Indeed, the JsonVariant returned by root["..."] has a special implementation of the == operator that knows how to compare string safely.
You can’t perform that action at this time.
0 commit comments