简体   繁体   中英

I am new to Flutter, I try to run my project on Android Studio but I get an error in the console like:

  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>

Obviously

JSON.decode(response.body);

returns a Map not a List

This

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

or

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

should fix your error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM