首页 > 解决方案 > 解析列表> 列出在飞镖/颤振中

问题描述

我有来自服务器的响应:

[
    [
        "2014",
        "01",
        "01"
    ],
    [
        "2015",
        "01",
        "01"
    ],
    [
        "2016",
        "01",
        "01"
    ]
]

我想将它们转换为列表。这就是我创建的:

final response = await _dio.get(
    "api/v1/calendar/holidays");
List<dynamic> list = response.data;
List<String> calendarList = List();
var dateList =
list.map((i) => ((a) => calendarList.add(a.toString()))).toList();

return calendarList;

但这会返回我的字符串列表。有任何想法吗?

标签: dartflutter

解决方案


var result = response.data
  .map((e) => DateTime.parse('${e[0]}-${e[1]}-${e[2]}'))
  .toList();

推荐阅读