dart - 转换列表到地图>
问题描述
我有这段代码按预期工作:
import 'package:postgres/postgres.dart';
main(List<String> arguments) async {
String host = "localhost";
int port = 5432;
String dbName = "quakedata";
String username = "postgres";
String password = "xxx";
var connection;
try {
connection = PostgreSQLConnection(host, port, dbName, username: username, password: password);
await connection.open();
var query = """select geojson from dm_quakefeatures order by modified_date desc limit 10""";
List<List<dynamic>> results = await connection.query(query);
for(final row in results){
for(final thisIsAMap in row){
print(thisIsAMap);
}
}
} catch (exception, stackTrace) {
print(exception);
print(stackTrace);
} finally {
connection.close();
}
}
我困惑的是这两点:
- 根据 postgres 包文档,方法
query()
应该返回Future<List<List>>
但返回List<List<dynamic>>
?为什么?这是因为await
? - 我知道在
thisIsAMap
变量中我将接收这种格式{ "properties": { "mag": 1.4, "place": "Southern Alaska", "time": 1544108572101, "updated": 1544108744865, "tsunami": 0, "type": "earthquake", "title": "M 1.4 - Southern Alaska" }, "geometry": { "type": "Point", "coordinates": [ -149.9893, 61.4013, 32.8 ] } }
的数据:这将完全适合Map<String, Map<String, dynamic>>
数据类型。我怎样才能把它转换成它?
解决方案
推荐阅读
- gnuplot - 如何仅使用线点和使用gnuplot的多个图绘制由ID列指定的点?
- reactjs - 如何使用 react-scripts 安装 NPM 插件
- docker - 我们可以控制 .dockerignore 文件中内容的区分大小写吗?
- c# - 无法将 C# 字符串从用户态传递到内核模式 C 并使用它来查找特定的 LDR_DATA_TABLE_ENTRY
- python - Flask 根据激活的按钮获得相同的页面结果
- mysql - 如果我们有多个重复的日期,如何确定所有详细信息都应该放在第一个项目中?
- python - 迭代时如何从列表中删除元素?
- tensorflow - TFLite 交叉编译 arm64 构建错误?
- sql - SQL Server,在时间戳中交换日期
- html - 图像不会缩小以适应带有响应页面的 DIV