在runtimeType中访问数据类型Response <dynamic>:Dio错误

时间:2020-11-09 22:54:35

标签: flutter dio

我正在发送一个与dio库错误的请求

发现错误时,我可以print(e.response);print(e.response.statusCode);

响应的runtimeType为Response<dynamic>

当打印响应时,我得到这样的信息

{"message":"there is message from the api here"}

我无法访问此消息以进行打印。

我尝试过

e.response.message and get错误。镖:167 Uncaught (in promise) Error: NoSuchMethodError: 'message'

e.response["message"]并获得Uncaught (in promise) Error: NoSuchMethodError: '[]'

我尝试对es.response进行json.encoding,但它也不起作用,如何访问类型Response<dynamic>内的数据

谢谢

1 个答案:

答案 0 :(得分:1)

改为使用e.response.data['...']来访问所需的数据,