作者:乐思GO_361 | 来源:互联网 | 2022-12-10 14:45
1> Richard Heap..:
如果您查看邮递员,您可能会看到Content-Type
服务器发送的http标头缺少encoding
标签.这会导致Dart http客户端将主体解码为Latin-1而不是utf-8.有一个简单的解决方法:
http.Response respOnse= await http.get('SOME URL',headers: {'Content-Type': 'application/json'});
List respOnseJson= json.decode(utf8.decode(response.bodyBytes));
实际上,只有Content-Type标头。使用`Content-Type:application / json` Dart将采用Latin-1编码。使用`Content-Type:application / json; charset = utf-8` Dart将使用指定的字符集将字节(response.bodyBytes)解码为字符(response.body)。解决方法是自己解码字节,因为您知道字符集为utf-8。