ESPAsyncWebServer
ESPAsyncWebServer copied to clipboard
code sample from "ArduinoJson Basic Response" does not compile
This page: https://me-no-dev.github.io/ESPAsyncWebServer/ Has this code:
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonBuffer jsonBuffer;
JsonObject &root = jsonBuffer.createObject();
root["heap"] = ESP.getFreeHeap();
root["ssid"] = WiFi.SSID();
root.printTo(*response);
request->send(response);
which does not build. with Arduino IDE 1.8.19 Error message:
error: cannot bind non-const lvalue reference of type 'ArduinoJson::V6213PB2::JsonObject&' to an rvalue of type 'ArduinoJson::V6213PB2::JsonObject'
JsonObject& root = response->getRoot();
This makes sense because getRoot() returns a JsonVariant which then needs to be temporarily converted to a JsonObject, but you can't bind a reference to a temporary object