Dart 2和解析json

Dart 2和解析json,dart,angular-dart,Dart,Angular Dart,我正在尝试使用Dart 2 for web将json解析为产品列表 我有以下课程: class Product { final String Problem; final String Owner; final String Description; const Product({ this.Problem, this.Owner, this.Description, }); factory Product.parse(Map<

我正在尝试使用Dart 2 for web将json解析为产品列表

我有以下课程:

class Product {

  final String Problem;

  final String Owner;

  final String Description;

  const Product({
    this.Problem, 
    this.Owner,
    this.Description,
  });


  factory Product.parse(Map<String, dynamic> json) {
    print(json);
    return new Product(
      Problem: json["Problem"],
      Owner: json["Owner"],
      Description: json["Description"]
    );
  }
}

您的JSON不包含任何列表,它都是映射。 当您尝试将
映射
强制转换为
列表
时,它必须失败,因为映射不是列表

也许你想做:

final productList = (jsonDecode(payload) as Map).values.toList();

这将为您提供一个产品映射列表,其中没有您似乎无论如何都不会使用的名称。

您的JSON不包含任何列表,而是所有映射。 当您尝试将
映射
强制转换为
列表
时,它必须失败,因为映射不是列表

也许你想做:

final productList = (jsonDecode(payload) as Map).values.toList();

这将为您提供一个产品映射列表,其中不包含您似乎无论如何都不会使用的名称。

因此,根据您的JSON负载,顶级元素是
Map
。i、 e.
“产品一号”
是一把钥匙。是吗?是的,是的。有解决方案吗?因此,根据JSON负载,顶级元素是
Map
。i、 e.
“产品一号”
是一把钥匙。是吗?是的,是的。有什么解决办法吗?
final productList = (jsonDecode(payload) as Map).values.toList();