【问题标题】:How to write in jsonDecode?jsonDecode怎么写?
【发布时间】:2021-08-09 03:28:58
【问题描述】:
{
  "success": true,
  "msg": {
    "name": "xxxx",
    "Id": "123",
  }
}

当我从 api 收到响应时,如何解码这种格式的响应?

使用时出现错误

**

Map map = json.decode(response.data);

**

错误:Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'

【问题讨论】:

  • 已解码,您正在尝试再次解码。
  • 我的意思是自动解码
  • 所以我们应该直接使用响应
  • 是的,你不用担心
  • 但是当我使用controller.storeDetails.toString() 时,它显示为空

标签: flutter flutter-layout flutter-test


【解决方案1】:

您需要解码正文而不是数据。

Map resultMap = jsonDecode(request.body);

像这样访问它

resultMap['success']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-04
    • 2021-11-05
    • 2019-01-15
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 2014-12-04
    相关资源
    最近更新 更多