无法访问嵌套数组对象抖动

问题描述 投票:0回答:2

我有一组数据,有一些详细信息,当我尝试显示一个值返回null时,其他2个数据都很好,但是如果我尝试显示其他数据,则显示为null,如果我尝试将其添加到setState ,所有内容都为空,当我可以显示它时,“ Description”,“ imagepath”没有问题,但是没有显示来自replys对象的数据]

JSON

{
  "doc": {
    "image": {
      "Description": "tested",
      "replay": " ",
      "Image_Rating": 0,
      "replay_status": 0,
      "Report_Date": "1591228800",
      "Status": 1,
      "_id": "5ed88ae73025a4445568ece3",
      "image_path": "http://xxx.xxx.xxx.xxx:xxx/area_images/1670281356001.jpg",
      "Created_User_Id": "5ed22c2507a33e2c1cf3a3a5",
      "Branch_Id": "5ed22bf807a33e2c1cf3a3a4",
      "image_temp_path": "http://xxx.xxx.xxx.xxx:xxx/area_images_temp/1670281356001.jpg",
      "Order_Id": 32425,
      "reg_date": "1591249638163",
      "Area_Id": "5dc11c4046c214298f85e2e0",
      "Section_Id": "5dc1097546c214298f85e2ae",
      "Report_Time_Type": 1,
      "mapperId": "5ed22c4207a33e2c1cf3a3a6",
      "Created_At": "Thursday, June 4th, 2020, 11:17:18 AM",
      "__v": 0
    },
    "replays": [
      {
        "replay": "Good\n",
        "Report_Date": "1590796800",
        "_id": "5ed248e0c1a47a3e8c4ce8bb"
      }
    ]
  }
}

代码

  Future<String> getImageView(String imageid) async {

    Future token = SharedPrefrence().getToken();

    token.then((data) async {
      var token = data;
      var response = await http.post(Urls.Image_Details,
          headers: {
            "Content-Type": "application/json",
            "Authorization": "Bearer $token",
          },
          body: json.encode({
            "imageId": imageid,
          }));


      if (response.statusCode == 200) {
        try {
          var resp = response.body;

          Map<String, dynamic> value = json.decode(resp);
          var name = value['doc']['image'];

          Description = name["Description"].toString();
          image_path = name["image_path"].toString();

          replay = name["replays"]["replay"].toString();


        setState(() {
          Description = name["Description"].toString();
          image_path = name["image_path"].toString();
//          replay = name["replays"]["replay"].toString();
        });



        } catch (e) {
          e.toString();
        }
      }
    });
    }

我有一组数据,有一些详细信息,当我尝试显示一个值返回null时,其他2个数据都很好,但是如果我尝试显示其他数据,则显示为null,如果我尝试将其添加到setState ,...

flutter flutter-layout
2个回答
0
投票

replays是一个数组。试试这个:name["replays"][0]["replay"]


0
投票

问题是 "replays": [ { "replay": "Good\n", "Report_Date": "1590796800", "_id": "5ed248e0c1a47a3e8c4ce8bb" } ]这是地图列表。因此,当我们访问列表中的第一个元素时,您应该使用

© www.soinside.com 2019 - 2024. All rights reserved.