如何在Dart代码中从REST API解码utf-8? [英] How to decode utf-8 from REST api in Dart code?
本文介绍了如何在Dart代码中从REST API解码utf-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用REST API从Wordpress网站创建新闻报道应用,但该应用是以UTF-8编码的.
I am trying to create a news report app from a Wordpress site using REST API but it is encoded in UTF-8.
我是Dart的新手,我所知道的是,我只能通过字符数组而不是通过输入字符串(作为输入)来解码Utf-8.那么如何为我的应用程序在Utf-8中解码字符串?
I am new in Dart, all I know is that I can decode Utf-8 just by an array of characters not by giving a string (as an input). Then how can I decode a string in Utf-8 for my app?
child: new Text(posts[index]["title"]['rendered'],
style: TextStyle(
fontSize: 21,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center),
),
new Padding(
padding: EdgeInsets.all(10.0),
child: new ListTile(
subtitle: new Text(posts[index]["excerpt"]
["rendered"]
.replaceAll(new RegExp(r'<[^>]*>'), '')),
),
),
这里是结果的图片: https://imgur.com/gallery/qxkc9yP
推荐答案
您可以获取正文字节并将其转换..
You can get the body bytes and convert it..
http.Response response = await _api.getData();
String source = Utf8Decoder().convert(response.bodyBytes);
// Convert to your class instance...
MyClass instance = json.decode(source);
这篇关于如何在Dart代码中从REST API解码utf-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文