flutter - 使用“|”解析令牌时出现格式异常 在 jsonDecode()
问题描述
使用“|”传递令牌时获取格式异常 在 jsonDecode() 中。
final SharedPreferences pref = await SharedPreferences.getInstance();
value = pref.get("token") as String;
if (value?.isEmpty ?? true) {
return null;
} else {
final Map<String, dynamic> map = await _parseJson(value);
return OldToken.fromJson(map);
}
static Future<Map<String, dynamic>> _parseJson(String text) {
return compute(_parseAndDecode, text);
}
static Map<String, dynamic> _parseAndDecode(String response) {
return jsonDecode(response) as Map<String, dynamic>;
}
解决方案
当您使用 SharedPreferences 时,您会直接检索一个字符串,因此您不需要解码一个 json 值。
推荐阅读
- javascript - 异步需求
- swift - Swift 5:如何释放由共享库分配的内存
- angular - 尝试打开 MatSnackBar 时 this._portalOutlet 未定义
- r - 如何将 NA 值替换为赋予相同 ID 的先前非 NA 值
- python - 查找每个客户拥有的最大产品数量
- android - 在主线程中访问协程时出现非法状态异常
- php - Laravel 刀片不尊重日期转换格式
- elasticsearch - 使用弹性搜索在多边形内拾取对象
- mongoose - GraphQL“ID 不能代表值...”错误,但突变工作正常
- python - 获取 Numpy 数组的所有组合