【问题标题】:Json.decode hangs while parsing JSON in Flutter在 Flutter 中解析 JSON 时 Json.decode 挂起
【发布时间】:2019-06-06 00:49:32
【问题描述】:

我的回复正文包含以下数据

[{"AttendanceID":null,"MobilePrefID":"Ab12949","DateTimeInString":"08/01/2019","DateTimeOutString":"08/01/2019","TimeIn":"18:16","TimeOut":"18:18","SignInAddress":null,"SignOutAddress":null}]

我的解码为 JSON 的代码如下

var dec = json.decode(resp.body)

但是,该命令卡在此处并且不会产生结果。

【问题讨论】:

  • 你有什么错误吗?请输入控制台输出
  • 什么都没有,没有抛出错误。
  • 添加更多代码来识别问题,如何获取数据?
  • 无法复制。上面的 JSON 很容易解码。试试flutter clean

标签: json flutter decode


【解决方案1】:

参考来自

"Unexpected Character" on Decoding JSON

并尝试了您的代码

 JsonCodec codec = new JsonCodec();
  try{
    String strBody = """[{"AttendanceID":null,"MobilePrefID":"Ab12949","DateTimeInString":"08/01/2019","DateTimeOutString":"08/01/2019","TimeIn":"18:16","TimeOut":"18:18","SignInAddress":null,"SignOutAddress":null}]""";
    print(strBody);
    var decoded = codec.decode(strBody);
    print("Decoded 1: $decoded");
  } catch(e) {
    print("Error: $e");
  }

你会得到结果

【讨论】:

  • 不产生错误:。一件有趣的事情当我打印 response.body 时,输出不完整。例如[{"AttendanceID":null,"MobilePrefID":"Ab12949","DateTimeInString":"08/01/2019","DateTimeOutString":"08/01/2019","TimeIn":"18:16" ,"TimeOut":"18:18","SignInAddress":null,"SignOutAddress":null},{"AttendanceID":null,"MobilePrefID":"Ab12949"
猜你喜欢
  • 2023-04-10
  • 2020-09-16
  • 2019-04-30
  • 2019-09-09
  • 2023-03-16
  • 2019-10-23
  • 1970-01-01
  • 2020-11-25
  • 2021-07-02
相关资源
最近更新 更多