dart - 解析列表> 列出在飞镖/颤振中
问题描述
我有来自服务器的响应:
[
[
"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;
但这会返回我的字符串列表。有任何想法吗?
解决方案
var result = response.data
.map((e) => DateTime.parse('${e[0]}-${e[1]}-${e[2]}'))
.toList();
推荐阅读
- python - Django 如何设置电子邮件
- javascript - 使用 Python Flask 进行 LDAP 身份验证 - 将密码保存在服务器内存之外
- css - 仅在移动设备上裁剪的元素 - 发生了什么?
- php - 从 PHP 中的 sshseclib 日志输出行中删除退格字符
- angular - 使用依赖的下拉菜单初始化 formGroup
- php - 如何将值从一个表单字段转移到 Laravel 中的另一个字段?
- google-chrome - 如何从 Outlook 加载项 (Office 365) 在 Chrome 浏览器中打开链接?
- javascript - 函数组件不支持 contextType
- java - 带有桌面应用程序的 Sqlite 数据
- javascript - 带有文件的表单-上传到 Json-字符串到 JavaBackend