Here is an example from FSBrowser that comes along with the ESP8266 library:
server.on("/all", HTTP_GET, []() {
String json = "{";
json += "\"heap\":" + String(ESP.getFreeHeap());
json += ", \"analog\":" + String(analogRead(A0));
json += ", \"gpio\":" + String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
json += "}";
server.send(200, "text/json", json);
json = String();
});
I'm not so interesting in what it is doing (I know that), but more the code structure itself.
First it defines a string String json ="something"; then it does json = String();
Does this have to do with freeing memory or something?
If so, in which cases is it necessary to do this?