将List <dynamic>转换为Map <string,map <string,=“” dynamic =“” >>

时间:2018-12-07 14:20:34

标签: 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();
 }
}

我困惑的是这两点:

  1. 根据postgres软件包documentation,方法query()应该返回Future<List<List>>但返回List<List<dynamic>>吗? 为什么?是因为await吗?
  2. 我知道在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>>数据类型。 如何将其转换为它?

0 个答案:

没有答案