【问题标题】:Flutter web json data not getitFlutter web json数据不getit
【发布时间】:2022-01-12 06:39:36
【问题描述】:

我是 Flutter Web 的新手,但这个错误太疯狂了,我获取 json 数据的功能是

@override
  Future<List<StoryEntity>> getNewAnimation(int id) async{
    print("ali");
    return (json.decode(
        (await http.Client().get(Uri.parse('https://hekayatname.ir/home/getanimation')))
            .body)['list'] as List)
        .map(
          (e) => StoryEntity(
        title: e['fullname'],
        imagePath: e['logo_url'],
        description: "e['description']",
        rating: 1,
        galleryImagesPath: [],
        id: e['id'],
        producer: e['address'],
      ),
    ).toList();
  }

但我一无所获。 在网络浏览器中,我的数据是这样的,只需转到此链接 https://hekayatname.ir/home/getanimation 我把代码改成这个

  Future<List<StoryEntity>> getNewAnimation(int id) async{
    print("1");
    final response = await http.Client().get(Uri.parse("https://hekayatname.ir/home/getaudioestory"));
    if(response.statusCode == 200){
      print("2");
    }
    else{
      print("3");
      print(response.statusCode);
    }
}

我对 if 和 else 都一无所知 如果不工作,否则不工作....需要帮助!

【问题讨论】:

    标签: json flutter rest web flutter-web


    【解决方案1】:

    Visit this link。复制您的 json 响应并粘贴到 json 部分。给出你的班级名称并点击 Generate Dart。

    现在点击复制 dart 代码并将其添加到您的项目中。然后你可以像在成功案例中一样使用它。

    注意如果您遇到Null 对象的任何错误。这意味着您的响应包含空值并将此数据类型替换为相应的数据类型。

        if(response.statusCode == 200){
          print('2');
          YourJsonResponse obj = YourJsonResponse.fromJson(jsonDecode(response.body));
        } else{
          print("3");
          print(response.statusCode);
        }
    

    【讨论】:

      猜你喜欢
      • 2021-02-04
      • 2020-12-19
      • 1970-01-01
      • 2020-12-31
      • 2021-05-04
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      • 2020-01-07
      相关资源
      最近更新 更多