小编Gai*_*inz的帖子

如何在flutter中从json反序列化对象列表

我使用dart包json_serializable进行json序列化.查看flutter文档,它显示了如何反序列化单个对象,如下所示:

Future<Post> fetchPost() async {
  final response =
  await http.get('https://jsonplaceholder.typicode.com/posts/1');

  if (response.statusCode == 200) {
  // If the call to the server was successful, parse the JSON
  return Post.fromJson(json.decode(response.body));
  } else {
    // If that call was not successful, throw an error.
    throw Exception('Failed to load post');
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,我对dart不太熟悉,无法弄清楚如何对项目列表而不是单个实例执行相同的操作.

json dart flutter

21
推荐指数
7
解决办法
2万
查看次数

标签 统计

dart ×1

flutter ×1

json ×1