【问题标题】:Getting Format Exception while parsing token with '|' in jsonDecode()使用“|”解析令牌时出现格式异常在 jsonDecode()
【发布时间】:2021-02-15 05:19:47
【问题描述】:

使用“|”传递令牌时获取格式异常在 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>;
  }

【问题讨论】:

  • 看不到您的问题,因为这里的图片被屏蔽了。最好以文本形式提供。
  • 我认为如果您可以发布失败的 JSON 输入片段,这将有助于其他人更好地理解。
  • 哪一行出错了??
  • 我在 jsonDecode() 方法@JanviPatel 中得到格式异常

标签: flutter flutter-dependencies dio


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    相关资源
    最近更新 更多