【发布时间】:2020-07-09 18:50:36
【问题描述】:
错误:发生异常。 _TypeError(类型'List'不是类型'Map'的子类型)
Future<Album> fetchAlbum() async{
final response = await http.get(Uri.encodeFull("192.168.43.106:8080/customers/"),
headers: { "Accept": "application/json" } );
if (response.statusCode == 200) {
return Album.fromJson(json.decode(response.body));
}
else{
throw Exception('Failed to load Album');
}
}
class Album {
final int id;
final String email;
final String name;
Album({this.id, this.email, this.name});
factory Album.fromJson(Map<String, dynamic> json){
return Album(
id: json['id'],
email: json['email'],
name: json['name'],
);
}
}
【问题讨论】:
-
在这里放一些你尝试过的代码而不是图片,并显示实际错误是什么
-
Future
fetchAlbum() async{ final response = await http.get( Uri.encodeFull("192.168.43.106:8080/customers/"), headers: { "Accept": "application/json" } ); if (response.statusCode == 200) { return Album.fromJson(json.decode(response.body)); }else{ throw Exception('Failed to load Album'); } } -
你能分享专辑模型代码以及来自 api 的响应吗?
-
@MuhammadNoman 以上是更新的代码。请帮忙