0

我有来自 api 的数据,如下所示:

   {
        "status": true,
        "error": "",
        "message": "Record Found.",
        "data": {
            "2021-Apr-19": [
                {
                    "img_url": "https://www.rezzap.com/uploads/profile-photo/BWPOFCyHMFm_OgzvCxRwS5dBJTS6wCgy.jpg",
                    "person": "CooperMac",
                    "message": " supported your activity drawing."
                }
            ],
            "2021-Mar-30": [
                {
                    "img_url": "https://www.rezzap.com/uploads/profile-photo/BWPOFCyHMFm_OgzvCxRwS5dBJTS6wCgy.jpg",
                    "person": "CooperMac",
                    "message": " commented on your activity Test Activity 12-11-2020."
                },
              {
                "img_url": "https://www.rezzap.com/uploads/profile-photo/BWPOFCyHMFm_OgzvCxRwS5dBJTS6wCgy.jpg",
                "person": "CooperMac",
                "message": " supported your activity ."
            },
            ],
    }
    }

同样,我制作了这样的模型-:

class Support {
  Support({
    this.data,
  });

  Map<String, List<Datum>> data;

  factory Support.fromJson(Map<String, dynamic> json) => Support(
        data: Map.from(json["data"]).map((k, v) =>
            MapEntry<String, List<Datum>>(
                k, List<Datum>.from(v.map((x) => Datum.fromJson(x))))),
      );
}

class Datum {
  Datum({
    this.imgUrl,
    this.person,
    this.message,
  });

  String imgUrl;
  String person;
  String message;

  factory Datum.fromJson(Map<String, dynamic> json) => Datum(
        imgUrl: json["img_url"],
        person: json["person"],
        message: json["message"],
      );
}

这是回应但我不知道如何在模型中解析它,我需要在这里更正,所以如果有人可以提供帮助

 Future<Support> getSupportActivityData() async {
    final response = await _helper.get(supportedActivityUrl);
    var responseData = response["data"];
    var list = responseData as Map<String, dynamic>;
    return Support.fromJson(list);
  }

我也尝试将返回类型设为“Future<Map<String, List>>”等,但它总是向我显示类型转换错误

我想获取该数据并将其显示为List,那么我如何在这个分组的 List 中显示它,因为它要求键作为 Header 并且值作为它的行?

4

2 回答 2

0

我用响应来的地方替换了我的功能-:

  Future<Support> getSupportActivityData() async {
    final response = await _helper.get(supportedActivityUrl);
    return Support.fromJson(response);
  }

我已经在模型中解析了 ["data"] 并且我正在做什么再次解析我的 repo 中的数据(响应即将到来)

于 2021-05-17T03:41:22.470 回答
0

尝试使用此代码将您首先拥有的地图转换为列表

这可能发生在后端响应中,或者您可以将其从颤振中转换为

var h=here_the_map_data.forEach((k,v) => here_The_list_variable.add(here_the_map_data(k,v)));

于 2021-05-14T15:11:19.990 回答