首页 > 解决方案 > 在 runtimeType 响应中访问数据: 迪奥错误

问题描述

我正在发送一个与 dio 库有关的请求

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

响应的 runtimeType 是Response<dynamic>

在打印响应时,我得到这样的东西

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

我无法访问此消息来打印它。

我试过了

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

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

我尝试了 json.encoding e.response,它也不起作用,我怎样才能访问类型内的数据Response<dynamic>

谢谢

标签: flutterdio

解决方案


改为使用e.response.data['...']以访问您想要的数据,


推荐阅读