http
http copied to clipboard
Issue Decoding Special Characters (response.body)
Issue decoding special characters such as:
ã --> didn't test with any other special chars, but should be happening too. Such as ç, õ, á, à, ó, í, and so on...
Code:
final response = await http.get(
serverUrl,
),
headers: {
"accept": "application/json;",
},
);
print(response.body); // prints { "title":"Não encontrado" } -- should be {"title":"Não encontrado"}
Expected:
{ "title": "Não encontrado" }
Reality:
{ "title":"Não encontrado" }
Found a workaround:
Use:
json.decode(utf8.decode(response.bodyBytes))}
Instead of:
json.decode(response.body);
It works like a charm!
I still think that the response.body should be able to decode any UTF-8 characters, so the issue exists, maybe some of the http library developers can confirm.
Because in my understanding, even with request headers {"charset": "utf-8"} it doesn`t decode from utf-8 what is kind of strange behaviour.
I haven't touched Flutter for a while, but I didn't realize this issue was not closed yet...
It's been there for at least 3 years now.
When will we be able to write jsonDecode(response.body) when the default for application/json is utf-8 even in the RFC?
I'm wondering why it hasn't been fixed.
I have a problem in this function, it was working 0.13.4 but now, it cannot work ,

https://github.com/dart-lang/http/blob/master/pkgs/http/lib/src/utils.dart#LL28C67-L28C73
so retarded
Found a workaround:
Use:
json.decode(utf8.decode(response.bodyBytes))}Instead of:
json.decode(response.body);It works like a charm!
I still think that the
response.bodyshould be able to decode any UTF-8 characters, so the issue exists, maybe some of the http library developers can confirm.Because in my understanding, even with request headers {"charset": "utf-8"} it doesn`t decode from utf-8 what is kind of strange behaviour.
thanks, it solves my Turkish character (ş, ı,ç etc) problems
the solution for me was this : https://pub.dev/packages/html_unescape
var unescape = HtmlUnescape();
var text = unescape.convert(response.body);
print(text);
final data = jsonDecode(text);