I am building a door sign for our Company's rooms which connects to a shared Office 365 calendar.
The string "Känel" results in "Ku00e4nel" when I parse the response of the Graph API using ArduinoJSON which doesn't support either UTF-8 nor UTF-16 but "u00e4" is Unicode so what is going on here?
The developer told me that parsed strings aren't touched so the output should work if the source is in UTF-8 which regarding the output apparently is not.
I have already tried setting the charset in the header but maybe I am not aware of further available options which would help me to get rid of my issue.
Code:
String response = "";
DynamicJsonBuffer JSONBuffer;
http.begin(graphAPI);
http.addHeader("Authorization", "Bearer " + token);
http.addHeader("Prefer", "outlook.timezone = \"Central Europe Standard Time\"");
http.addHeader("Content-type", "application/json; charset=UTF-8");
int httpResponseCode = http.GET();
if (httpResponseCode = 200) {
response = http.getString();
JsonObject& parsed = JSONBuffer.parseObject(response);
if (parsed.success()) {
for (int i = 0; i < parsed["value"].size(); i++) {
String startTime = parsed["value"][i]["start"]["dateTime"];
startTime = startTime.substring(11, 16);
String endTime = parsed["value"][i]["end"]["dateTime"];
endTime = endTime.substring(11, 16);
String subject = parsed["value"][i]["subject"];
next_y += 35;
display_u8.setCursor(static_x, next_y);
display_u8.print(startTime + " - " + endTime + " " + subject);
}
} else {
display_u8.println("Parsing failed");
}
Sample Response:
"value": [
{
"@odata.etag": "W/"Npd9zqlLQE+/S5XEMoC9AAAAIkfORw=="",
"id": ".............",
"subject": "von Känel Sacha ",
"start": {
"dateTime": "2019-02-11T13:00:00.0000000",
"timeZone": "Central Europe Standard Time"
},
"end": {
"dateTime": "2019-02-11T14:00:00.0000000",
"timeZone": "Central Europe Standard Time"
}
},
{
"@odata.etag": "W/"Npd9zqlLQE+/S5XEMoC9AAAAIkfOiQ=="",
"id": ".............",
"subject": "von Känel Sacha ",
"start": {
"dateTime": "2019-02-11T15:00:00.0000000",
"timeZone": "Central Europe Standard Time"
},
"end": {
"dateTime": "2019-02-11T16:00:00.0000000",
"timeZone": "Central Europe Standard Time"
}
}
],
}
The parsed strings should be displayed as "von Känel Sacha" and not as "von Ku00e4nel Sacha".
Edit: I just discovered that the source of the problem is the Microsoft Graph API itself which encodes the character "ä" as \u00e4 but that's wrong in my opinion keeping in mind I set the charset to UTF-8 which will not work with that Unicode representation.