How to Map Flutter JSON Strings from List?

前端 未结 3 813
遥遥无期
遥遥无期 2021-02-10 11:09

I\'m successfully printing my response as String from my YouTube JSON url, but when I try to serialize through the \"items\" I get the following error Unhandled exception:

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 12:07

    It looks like data['items'] is a List (i.e. a JSON Array), not a Map.

    You can use list comprehension methods to help here:

    final items = (data['items'] as List).map((i) => new CardInfo.fromJson(i));
    for (final item in items) {
      print(item.id);
    }
    

提交回复
热议问题