html - Flutter http response.body utf8 编码错误
问题描述
我开始学习 Flutter,并通过制作自己的manga
阅读应用程序来做到这一点,其中我从我最常使用的网站上抓取所有数据。
我的问题是,mangas
由于这个错误,我读到的只有一个我无法抓取数据:
FormatException (FormatException: Bad UTF-8 encoding 0x22 (at offset 369))
我的刮板代码:
Future<Manga> getMangaInfo(source) async{
final response = await _client.get(source);
var manga;
print(response.body);//error occurs here
final document = parse(response.body);
final mangaInfo = document.getElementsByClassName('tamanho-bloco-perfil');
for(Element infos in mangaInfo){
final infoCont = infos.getElementsByClassName('row');
//get titulo
Element tituloCont = infoCont[0];
final tituloH = tituloCont.getElementsByTagName('h2');
Element tituloCont2 = tituloH[0];
String titulo = '['+tituloCont2.text+']';
//print(titulo);
//get capa
Element capaCont = infoCont[2];
final capaImg = capaCont.getElementsByTagName('img');
Element capaCont2 = capaImg[0];
final capaUrl = capaCont2.attributes['src'];
//get caprecente
final capsPorNumero = document.getElementsByClassName('row lancamento-linha');
final caps = capsPorNumero[0].getElementsByTagName('a');
Element info = caps[0];
final numero = info.text.split(' ')[1];
final capRecenteUrl = info.attributes['href'];
manga = Manga(null,source,titulo,capaUrl,numero,capRecenteUrl);
}
return manga;
}
response.body
给出错误的那个
我也尝试过使用response.bodyBytes
和解码,但仍然无法修复
这是该页面的链接: https ://unionleitor.top/perfil-manga/kimetsu-no-yaiba
我猜问题是html头上以下元标记上的�字符
<meta name="description" content="Kimetsu no Yaiba - Novo mangá sobrenatural da Shonen Jump. O mangá conta a história de Tanjiro, o filho mais velho de uma família que �">
我还没有找到解决方案,也许我只是看错了地方。谁能帮我解决这个问题?
谢谢!
解决方案
我只是做:
utf8.decode(response.bodyBytes);
即使你得到一个 JSON
jsonDecode(utf8.decode(response.bodyBytes))
推荐阅读
- javascript - 更改谷歌帐户后反应本机firestore不上传数据
- azure - Azure DevOps Pipeline:是否可以将构建部署到 Azure 以外的其他服务?
- odata - o为 VizFrames 展开数据
- android - isOpen 函数对 Room 数据库或 SQLite 有效吗?
- json - 使用 Microsoft-Avro-Core 进行序列化时包括命名空间属性
- wikipedia - 从 Wikipedia 页面获取干净的摘录
- ansible - 为什么 Ansible/jinja2 在 shell 块内复制文本?
- java - Java - Selenium - 无法找到 CDP 版本 94 的完全匹配,因此返回找到的最接近的版本:93
- gitlab - 是否可以在 renovate-runner 中为“Github-URL”定义代理 URL?
- c++ - 从另一个类初始化 C++ 类属性