某些字符未正确加载

Some of character is not load correctly

下面的示例在我的列表视图中加载数据,但某些字符无效,例如。 Å Ä 我正在尝试使用 utf8

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

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

当我使用 utf8 时,结果是正确的,但是我在 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);

有什么解决办法吗?

您的服务器可能没有使用 content-type 指定字符集,因此 http 包默认为 Latin-1

合并上面给出的两个部分。使用 utf8.decode 将字节解码为字符串,然后将该字符串作为 JSON 解码为使用 json.decode.

的映射
  var jsonData = json.decode(utf8.decode(response.bodyBytes));