【发布时间】:2020-12-22 12:48:29
【问题描述】:
在我的项目中,我得到了我的 json 字符串,后来我尝试为它分配一个 jsonResponse 变量,但出现如下错误:无法将参数类型“响应”分配给参数类型“字符串”。
这是我的代码:
Future getMahalle() async {
BaseOptions options = new BaseOptions(
baseUrl: globals.PROD_URL,
connectTimeout: 5000,
receiveTimeout: 3000,
);
Dio dio = new Dio(options);
dio.options.headers["Authorization"] = "Bearer ${globals.USER_TOKEN}";
try {
var response =
await dio.get(globals.SELECT_URL); //'api/hizlirapor/selects'
final jsonResponse = jsonDecode(response); //Here is the error line
MahalleModel mahalleList =
MahalleModel.fromJson(jsonDecode(response.data['mahalle']));
return mahalleList;
} on DioError catch (e) {
debugPrint("ERRORR!!!!!!!!!!!!! ${e.error.toString()}");
return null;
}
}
例如,我正在尝试实施this 文章并陷入困境。感谢您的帮助!
【问题讨论】:
标签: json api flutter asynchronous dart