Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.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
Flutter 来自服务器响应的颤振返回数组_Flutter - Fatal编程技术网

Flutter 来自服务器响应的颤振返回数组

Flutter 来自服务器响应的颤振返回数组,flutter,Flutter,在我的代码的这一部分等待webApi.getKeywords()返回可以从服务器获取的数组,现在当我尝试返回时,我得到错误: type 'List<dynamic>' is not a subtype of type 'String' 返回响应。正文: [ { "id": 1, "user_id": 1, "title": "asdasdasd", "description": "asdasdasd", "type": "post",

在我的代码的这一部分
等待webApi.getKeywords()返回可以从服务器获取的数组,现在当我尝试返回时,我得到错误:

type 'List<dynamic>' is not a subtype of type 'String'
返回
响应。正文

[
  {
    "id": 1,
    "user_id": 1,
    "title": "asdasdasd",
    "description": "asdasdasd",
    "type": "post",
    "slug": "asdasdad",
    "featured_images": {
      "images": {
        "300": "/uploads/post_images/2019/300_1573573784.png",
        "600": "/uploads/post_images/2019/600_1573573784.png",
        "900": "/uploads/post_images/2019/900_1573573784.png",
        "original": "/uploads/post_images/2019/1573573784.png"
      },
      "thumbnail": "/uploads/post_images/2019/300_1573573784.png"
    },
    "lang": "fa",
    "visit": 0,
    "categories": [
      {
        "id": 1,
        "title": "aaaaaaa",
        "lang": "fa",
        "parent": 0,
        "pivot": {
          "contents_id": 1,
          "content_categories_id": 1
        }
      }
    ]
  },
  {
    "id": 2,
    "user_id": 1,
    "title": "asdasdasd",
    "description": "asdadasd",
    "type": "post",
    "slug": "asdasdasda",
    "featured_images": {
      "images": {
        "300": "/uploads/post_images/2019/300_1573573846.png",
        "600": "/uploads/post_images/2019/600_1573573846.png",
        "900": "/uploads/post_images/2019/900_1573573846.png",
        "original": "/uploads/post_images/2019/1573573846.png"
      },
      "thumbnail": "/uploads/post_images/2019/300_1573573846.png"
    },
    "lang": "fa",
    "visit": 0,
    "categories": [
      {
        "id": 2,
        "title": "bbbbbbbb",
        "lang": "fa",
        "parent": 0,
        "pivot": {
          "contents_id": 2,
          "content_categories_id": 2
        }
      }
    ]
  }
]
问题出在这行代码上:

json.decode(response.body)
试试这个:

list = List<KeywordsResponse>.from(response.body.map((x) => KeywordsResponse.fromJson(x)));
list=list.from(response.body.map((x)=>KeywordsResponse.fromJson(x));

json.decode
不需要,因为
response.body
已经解码了的
列表
maps@pskink我想将
response.body
返回为
List
formatso调用
response.body
上的
map()
方法(已对映射的
List
进行json解码)@pskink
response.body.map((item)=>list.add(关键字response(item['id'],item['title'],item['description']))不起作用
response.body.map((item)=>KeywordsResponse.fromJson(item)).toList()
甚至更好:
response.body.map(关键字response.fromJson).toList()但我不能100%确定它是否有效
json.decode(response.body)
list = List<KeywordsResponse>.from(response.body.map((x) => KeywordsResponse.fromJson(x)));