关于 flutter 解析json数据报错 type ‘String‘ is not a subtype of type ‘int‘ of ‘index‘

在使用Flutter进行网络请求时,遇到类型错误:'String' is not a subtype of type 'int' of 'index'。问题出在尝试从响应数据中直接获取json键值,但实际响应数据是带转义符的String。解决方案是使用dart:convert库的jsonDecode方法将String转换为JSON数据,从而正确解析。
摘要由CSDN通过智能技术生成

刚入手code flutter,参考网上代码封装了dio,搭建了一个网络框架,但是在解析数据时总是报错 type 'String' is not a subtype of type 'int' of 'index',网上找了很久,唯一一篇相关的需要付费才能看,所以只能自己找找问题了。

请求的数据,拷贝出来粘贴到文本文件中,显示如下:

{"errCode":0,"errMsg":"","data":{"auditVersion":"1.1.2","neteaseAccid":"fa5d1eb9","uid":113522,"bankReqSignKey":"3w8Qc!w!","deactivating":false,"accessToken":"18l7SZOy3z6y2z8XxOKXms6eUkcbVmEKj5gtdh+eooObD6c2CO8g4duP14pzwsg+DgW6oD/lWwZxlup/e8HsPbfhVFHmBiigDEitpsRdFe1i16JGEH+IN8VXMAM0dMRq","neteaseToken":"b7046fb8fa01c5c8975fdb63a2138541"}}

看起来是正常json数据,并无异常,也不存在网上的所说的观点,数据类型错误。

公共解析拦截器代码如下:

import 'package:dio/dio.dart';
import 'result_data.dart';

class ResponseInterceptors extends InterceptorsWrapper {
  @
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值