我正在尝试向我的 Text()
显示来自 api 的正确阿拉伯语/波斯语单词。就英语而言,一切正常,但随着语言的变化,它会返回类似 LATIN1 的内容。
我已经按照这个问题来纠正我的问题:Invalid Arabic characters With Utf-8 charset Retrived with http.get Flutter
我有一个来自 API 的字符串 name
。它的酒吧名称为:Bar Beirut - بار بيروت
。但在响应中,我得到了上面的屏幕截图。
我曾尝试先对字符串进行编码,然后对其进行解码,但没有成功。
var encoded = utf8.encode(data['name']);
this.name = utf8.decode(encoded);
所以我在我的 Text()
中使用了 this.name
,但它显示英文字符,对于阿拉伯语,它显示 LATIN1。任何帮助,将不胜感激。谢谢
最佳答案
试试下面的方法,它适用于阿拉伯字符
return http.get(Uri.encodeFull(baseUrl), headers: {
"Content-Type": "application/json",
}).then((response) {
return json.decode(utf8.decode(response.bodyBytes));
});
关于utf-8 - 文本中出现无效的阿拉伯语/波斯语单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55645659/