Worked as expected for me.
const char tempC[] = "37°C";
Serial.println(tempC);
JsonDocument doc;
doc["temp"] = tempC;
uint8_t buf[100];
size_t len = serializeJson(doc, buf);
log_buf_i(buf, len); // available with ESP32 at least
HTTPClient http;
if (http.begin("http://httpbin.org/anything")) {
http.addHeader("Content-Type", "application/json");
Serial.printf("status %d\n", http.POST(buf, len));
Serial.println(http.getString());
}
Serial Monitor
37°C
First, does the Serial Monitor print the symbol? Yes.
0x7b, 0x22, 0x74, 0x65, 0x6d, 0x70, 0x22, 0x3a, 0x22, 0x33, 0x37, 0xc2, 0xb0, 0x43, 0x22, 0x7d, // {"temp":"37..C"}
See the 0xc2, 0xb0? That the UTF-8 encoding of U+00B0, the degree symbol. At the end there is "37..C": instead of that symbol is two dots. One for each of those two octets, which by themselves, have no character to display. (A few different possibilities for exactly why, but not that important).
Sending the JSON to an echo service at httpbin.org, the raw "data" has \u00b0, which is the expected JSON encoding. (Note that the Content-Length of what was sent is 16, which is the number of hex octets above. There are 24 characters between the quotes. 4 are the double-quote-escaping backslashes, so there are four more characters. The response itself is JSON, so it is replacing the two UTF-8 octets sent with the six octets of the \u encoding.)
status 200
{
"args": {},
"data": "{\"temp\":\"37\u00b0C\"}",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "identity;q=1,chunked;q=0.1,*;q=0",
"Content-Length": "16",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "ESP32HTTPClient",
"X-Amzn-Trace-Id": "Root=1-6603c664-596b67e1450b36e906c3258c"
},
"json": {
"temp": "37\u00b0C"
},
"method": "POST",
"origin": "172.8.222.85",
"url": "http://httpbin.org/anything"
}
which is also present in the resulting parsed "json".
If you put the symbol at the very top of the file
// 37°C
and dump the bytes, do you get the c2 b0?
$ hexdump -C degree.ino | head -n 1
00000000 2f 2f 20 33 37 c2 b0 43 0a 23 69 6e 63 6c 75 64 |// 37..C.#includ|
Is your editor saving in UTF-8?