首页 > 解决方案 > 使用“|”解析令牌时出现格式异常 在 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>;
  }

标签: flutterflutter-dependenciesdio

解决方案


当您使用 SharedPreferences 时,您会直接检索一个字符串,因此您不需要解码一个 json 值。


推荐阅读