如何在Dart代码中从REST API解码utf-8?

用户名

我正在尝试使用REST API从Wordpress网站创建新闻报道应用程序,但它以UTF-8编码。

我是Dart的新手,我所知道的是,我只能通过字符数组而不是通过输入字符串(作为输入)来解码Utf-8。那么如何为我的应用程序在Utf-8中解码字符串?

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

收成

您可以获取主体字节并进行转换。

 http.Response response = await _api.getData();
 String source = Utf8Decoder().convert(response.bodyBytes);

 // Convert to your class instance...
 MyClass instance = json.decode(source);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章