Flutter FormatException: Unexpected character (at character 2)

简介: Flutter FormatException: Unexpected character (at character 2)

异常

Unhandled Exception: FormatException: Unexpected character (at character 2)


分析

flutter json报以上错误,我这里是请求登录的接口,登录成功data中返回个人信息,失败data为null。


当出现这个异常的时候,首先的直觉就是data类型定义错误,还尝试过泛型。。



实际上这个坑是dio埋下的,但是在报错中又毫无dio的身影。。



解决

dio作为一个网络框架,一般在使用的时候我们都会做基础配置,其中有一项配置就是如何接收响应数据


responseType: ResponseType.json,


表示期望以哪种格式(方式)接受响应数据。接受4种类型 json, stream, plain, bytes. 默认值是 json,



但是像登陆这种返回是密文形式的数据,我们就需要修改type为plain,转为字符串解析(utf8)。


responseType: ResponseType.plain,


responseType 在 options 中配置


目录
相关文章
|
7天前
|
存储 Swift iOS开发
Swift 字符(Character)
10月更文挑战第26天
20 4
|
2月前
|
Python
8-7|TypeError: The fill character must be a unicode character, not bytes
8-7|TypeError: The fill character must be a unicode character, not bytes
Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation
Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation
73 0
|
小程序 算法 Go
Golang微信小程序数据解密报错:invalid character “‘p‘“ looking for beginning of value
Golang微信小程序数据解密报错:invalid character “‘p‘“ looking for beginning of value
496 0
|
前端开发
CSS安装出错:Unicode Character Check -> Your temp directory path contains Unicode characters........
CSS安装出错:Unicode Character Check -> Your temp directory path contains Unicode characters........
480 0
|
关系型数据库 MySQL Shell
[ERROR] COLLATION ‘utf8_unicode_ci‘ is not valid for CHARACTER SET ‘latin1‘
[ERROR] COLLATION ‘utf8_unicode_ci‘ is not valid for CHARACTER SET ‘latin1‘
|
网络安全
Bad escape character ‘ygen‘
Bad escape character ‘ygen‘
Bad escape character ‘ygen‘
|
API
Character 方法
Character 方法
94 0
|
Python
arserWarning: Falling back to the ‘python‘ engine because the ‘c‘ engine does not support regex sepa
arserWarning: Falling back to the ‘python‘ engine because the ‘c‘ engine does not support regex sepa
130 0
arserWarning: Falling back to the ‘python‘ engine because the ‘c‘ engine does not support regex sepa
|
SQL 关系型数据库 MySQL
mysql: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '= 的解决
昨天把mysql里所有table的varchar字段的字符集,批量换成了utf8mb4/utf8mb4_unicode_ci ,以便能保存一些emoji火星文 , 结果有一个sql语句执行时,报错如下: Illegalmixofcollations (utf8_unicode_ci,IMPLICI...
2134 0