Skip to content

Issue Decoding Special Characters (response.body) #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lcsvcn opened this issue Sep 9, 2022 · 7 comments
Closed

Issue Decoding Special Characters (response.body) #789

lcsvcn opened this issue Sep 9, 2022 · 7 comments
Labels
next-breaking-release Issues that are worth doing but need to wait for a breaking version bump

Comments

@lcsvcn
Copy link

lcsvcn commented Sep 9, 2022

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" }

@lcsvcn
Copy link
Author

lcsvcn commented Sep 9, 2022

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.

@lcsvcn lcsvcn closed this as completed Sep 9, 2022
@lcsvcn lcsvcn reopened this Sep 9, 2022
@aoisensi
Copy link

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.

@utkudenis
Copy link

I have a problem in this function, it was working 0.13.4 but now, it cannot work ,
image

medz pushed a commit to medz/prisma-dart that referenced this issue Mar 21, 2023
@medz
Copy link

medz commented Mar 21, 2023

@FlutterWiz
Copy link

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.

thanks, it solves my Turkish character (ş, ı,ç etc) problems

@abdoutech93
Copy link

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);

@brianquinlan
Copy link
Collaborator

Fixed in b7cdf61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next-breaking-release Issues that are worth doing but need to wait for a breaking version bump
Projects
None yet
Development

No branches or pull requests

8 participants