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

use*_*273 7 html utf-8 dart flutter

我正在尝试使用 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'<[^>]*>'), '')),
                            ),
                          ),
Run Code Online (Sandbox Code Playgroud)

这是结果的图片:https : //imgur.com/gallery/qxkc9yP

sie*_*ega 19

您可以获取正文字节并将其转换..

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

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

Run Code Online (Sandbox Code Playgroud)