Hallo zusammen.
Ich habe mir ein epaper Display geholt und spiele gerade damit rum. Ziel ist es von einem Server Daten zu holen, die das ESP32 Driver Board (Waveshare) auf dem epaper anzeigt. Soweit funktioniert das ganz gut. Die Daten kommen per JSON und werden per 'JSON.parse' geparsed.
Mein Problem ist, das die Anführungsstriche (vorn und hinten) im String bleiben und auch angezeigt werden. Das ist natürlich "unschön".
Daher meine Frage: Wie kriege ich die Anführungsstriche aus den Strings raus?
Beispiel-Payload vom Server:
{"time":"10:12:39","date":"22.05.2023"}
(Test)Codefragment der das JSON parsed:
if (WiFi.waitForConnectResult() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverName); //Specify the URL
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
else {
display.setFont(&FreeSansBold24pt7b);
display.setTextColor(GxEPD_RED);
y = y + 30;
display.setCursor(x, y);
display.print("Error on HTTP request");
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
JSONVar myObject = JSON.parse(payload);
Serial.println(myObject);
// JSON.typeof(jsonVar) can be used to get the type of the var
if (JSON.typeof(myObject) == "undefined") {
display.setFont(&FreeSansBold24pt7b);
display.setTextColor(GxEPD_RED);
y = y + 30;
display.setCursor(x, y);
display.print("JSON undefined");
} else {
Serial.print("JSON object = ");
Serial.println(myObject);
// myObject.keys() can be used to get an array of all the keys in the object
JSONVar keys = myObject.keys();
display.setFont(&FreeSans9pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(10, 20);
display.print("Datum: " + (String)JSON.stringify(myObject["date"]));
display.setCursor(10, 40);
display.print("Zeit: " + JSON.stringify(myObject["time"]));
for (int i = 0; i < keys.length(); i++) {
JSONVar value = myObject[keys[i]];
y = y + 20;
display.setFont(&FreeSans9pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(30, y);
display.print(keys[i]);
display.setCursor(150, y);
display.print(value);
Serial.print(keys[i]);
Serial.print(" = ");
Serial.println(value);
}
}
} else {
y = y + 60;
display.setFont(&FreeSansBold24pt7b);
display.setTextColor(GxEPD_RED);
display.setCursor(50, y);
display.print("WiFi Disconnected");
}
Angezeigt wird :
Datum: "22.05.2023"
Vielen Dank schon mal.