Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 颤振中json解析期间的类型不匹配_Dart_Flutter - Fatal编程技术网

Dart 颤振中json解析期间的类型不匹配

Dart 颤振中json解析期间的类型不匹配,dart,flutter,Dart,Flutter,我有一个json作为列表返回。我正试图解析它,但我得到一个名为 List data = json.decode(response.body) as List; var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList(); _InternalLinkedHashMap不是“List”类型的子类型 这是我的密码- List data = json.decode(response.body

我有一个json作为列表返回。我正试图解析它,但我得到一个名为

 List data = json.decode(response.body) as List; 
    var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList();
_InternalLinkedHashMap不是“List”类型的子类型 这是我的密码-

 List data = json.decode(response.body) as List; 
    var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList();
还有我的json模型类

 List data = json.decode(response.body) as List; 
    var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList();
    class NewsList {
  final List<News> news;

  NewsList({
    this.news,
  });

  factory NewsList.fromJson(List<dynamic> parsedJson) {

    List<News> news = new List<News>();
    news = parsedJson.map((i)=>News.fromJson(i)).toList();

    return new NewsList(
        news: news
    );
  }
}

class News{
  final String status;
  final String type;

  News({
    this.status,
    this.type
  }) ;

  factory News.fromJson(Map<String, dynamic> json){
    return new News(

      status: json['status'],
      type: json['type'],
    );
  }}  

                                                                                                                                                                also this is how json is returning                                                                                                                    
类新闻列表{
最终名单新闻;
新闻列表({
这条新闻,,
});
factory NewsList.fromJson(List parsedJson){
列表新闻=新列表();
news=parsedJson.map((i)=>news.fromJson(i)).toList();
返回新新闻列表(
新闻:新闻
);
}
}
班级新闻{
最终字符串状态;
最终字符串类型;
新闻({
这个,身份,,
这个.类型
}) ;
factory News.fromJson(映射json){
返回新消息(
状态:json['status'],
类型:json['type'],
);
}}  
这也是json返回的方式
[ { “id”:10159, “日期”:“2018-07-23T11:34:22”, “日期”:“2018-07-23T11:34:22”, “guid”:{ “呈现”:” }, “修改”:“2018-07-23T11:35:13”, “修改后的格林尼治标准时间”:“2018-07-23T11:35:13”, “鼻涕虫”:“只有25卢比的儿童会因缺乏血液而被移除”, “状态”:“发布”, “类型”:“职位”、…]

 List data = json.decode(response.body) as List; 
    var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList();

我已经根据Dart 2.0文档明确声明了传递的数据类型,但仍然存在错误。

首先,删除
var
,这只会降低可读性。
 List data = json.decode(response.body) as List; 
    var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList();
从我看到的情况来看,您将收到一个json新闻列表,然后将其映射为
list
,然后您希望遍历该列表并创建一个
新闻列表的列表

 List data = json.decode(response.body) as List; 
    var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList();
相反,您应该只从列表中创建一个
NewsList
对象,就像您设计的那样:)

 List data = json.decode(response.body) as List; 
    var newsPageViewResult = data.map((i) => new NewsList.fromJson(i)).toList();