我是Flutter的新手,我尝试在Android Studio上运行我的项目但是在控制台中出现错误,如:

时间:2018-05-14 12:39:21

标签: android-studio dart flutter

  Future<String> getData() async {
http.Response response = await http.post(
Uri.encodeFull("https:.........."),
    headers: {
  "Accept" : "application/json"

}
,body: {
  "email" : "test123@gmail.com",
  "password" : "password123"
}

);

List data = JSON.decode(response.body);
print(data[0]["access_token"]);

}

ERROR:    '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>

1 个答案:

答案 0 :(得分:2)

显然

JSON.decode(response.body);

返回Map而不是List

var data = JSON.decode(response.body);

Map<String, dynamic> data = JSON.decode(response.body);

应该修复你的错误。