[英]flutter get data from api and assign to array
List data;列出数据;
i want to show response but when i try to assign jasonResponse to data i get this error我想显示响应,但是当我尝试将 jasonResponse 分配给数据时出现此错误
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'List' is not a subtype of type 'Map' [错误:flutter/lib/ui/ui_dart_state.cc(148)] 未处理的异常:类型“列表”不是“地图”类型的子类型
so what should i do所以我该怎么做
how to assign array of object to data如何将 object 的数组分配给数据
Future<String> getJsonData() async{
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
Map data = {'sale_id': sharedPreferences.getInt("token")};
var jsonResponse;
var response = await http.post(
"http://",
body: json.encode(data),
headers: {
"Content-Type": "application/json"
},
);
if (response.statusCode == 200) {
jsonResponse = json.decode(response.body);
print('jsonRespnse');
print(jsonResponse['developer_list']);
if (jsonResponse != null) {
setState(() {
data = jsonResponse['developer_list'];
});
Your data
is a type Map
but you are assigning a type List
.您的data
是类型Map
但您正在分配类型List
。
Simply, add a key with your value, like below:只需添加一个带有您的值的键,如下所示:
data['developer_list'] = jsonResponse['developer_list'];
Make sure to access that list by data['developer_list']
确保通过data['developer_list']
访问该列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.