【问题标题】:How to get data using Flutter from api using Json Serializable如何使用 Flutter 从 api 使用 Json Serializable 获取数据
【发布时间】:2022-01-04 04:34:34
【问题描述】:

我遇到了一个问题,如何在 Flutter 中使用 json 可序列化包生成和使用数据模型类

{
"listNavigationalCatalogs": {
  "items": [
    {
      "catalogCategories": {
        "items": [
          {
            "categoryTheme": {
              "backgroundColor": {
                "blue": 226,
                "green": 215,
                "red": 163
              },
              "descriptionColor": null,
              "indicatorColor": {
                "red": 54,
                "green": 186,
                "blue": 228
              },
              "selectedColor": null,
              "unSelectedColor": null
            },
            "description": "Adventure Sports",
            "button": {
              "color": {
                "blue": 228,
                "green": 186,
                "red": 54
              },
              "text": "SEE ALL",
              "textColor": null
            },
            "image": "https://i.postimg.cc/pLjSRBvn/adv.jpg",
            "name": "Adventure",
            "priority": 3,
            "_deleted": null
          }
        ]
      },
      "version": 1,
      "interval": 1,
      "fetchedDate": "2021-11-25T00:00Z",
      "fetchRealTime": false,
      "expiryDate": "2021-11-25T00:00Z"
    }
  ]
}

}

我是新手,请帮助我如何使用它我想从所有项目中获取数据 -->catalogCategories--> 项目 --> 名称。 我正在尝试获取数据来为我的目录生成标签栏

【问题讨论】:

  • 如果您从 API 获取数据,请参考我的回答 here 或 here 或 here 希望对您有所帮助

标签: json flutter dart serialization


【解决方案1】:

使用 https://quicktype.io/ 并选择 dart 进行 json 序列化

【讨论】:

  • 我有所有的模型,但问题是我只进入目录目录项目而不是整体项目。我想要 Items [catalogCategories] 数组元素。
猜你喜欢
  • 2019-09-04
  • 2019-10-16
  • 2017-11-30
  • 1970-01-01
  • 2019-09-16
  • 1970-01-01
  • 2021-06-17
  • 1970-01-01
相关资源
最近更新 更多