Some of character is not load correctly

151

Your server is likely not specifying the charset with the content-type, so the http package is defaulting to Latin-1.

Combine the two parts you gave above. Decode the bytes to a string with utf8.decode, then decode that string as JSON to a map with json.decode.

  var jsonData = json.decode(utf8.decode(response.bodyBytes));
Share:
151
babayaro
Author by

babayaro

Updated on December 16, 2022

Comments

  • babayaro
    babayaro over 1 year

    Example below loads data in my listview but some of the characters are invalid eg. Å Ä I'm trying to use utf8

    var jsonData = json.decode(response.body);
    
    var jsonData = utf8.decode(response.bodyBytes);
    

    when I use utf8, result is correct but I get quotation mark and get error while load data in listTile

    //I/flutter ( 4629): {"items":[{"name":"xyšć",  //character is OK but get quotation mark
    //I/flutter ( 4629): {items: [{name: xyÄÄ,  //wrong character
    
    
    
    class Api {
      static Future<dynamic> _get(String url) async {
        try {
          final response = await http.get(url);
          var jsonData = json.decode(response.body);
    

    Any solution?

    • Richard Heap
      Richard Heap over 4 years
    • Richard Heap
      Richard Heap over 4 years
      As an aside, it's not considered good Dart style to create classes (like your Api) that just contain static methods. Just make their functions top-level functions.