【发布时间】:2021-11-04 15:42:39
【问题描述】:
当我尝试解码 JSON 时,出现此错误:
需要一个“FutureOr
”类型的值,但得到一个“_JsonMap”类型的值
这是我从 API 获取数据的代码:
Future<List> getData() async {
final prefs = await SharedPreferences.getInstance();
final key = 'token';
final value = prefs.get(key) ?? 0;
String myUrl = "$serverUrl/userchecks";
http.Response response = await http.get(Uri.parse(myUrl), headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $value'
});
print('Response status : ${response.statusCode}');
return json.decode(response.body);
}
【问题讨论】:
-
分享您的 JSON 响应。