繁体   English   中英

在颤振中从网络获取所有 json 数据

[英]Get all json data from web in flutter

您好,我正在尝试从此页面获取所有 json 数据:

https://www.espn.com/soccer/team/_/id/4438&xhr=1

但在 response.body 中只包含 json 的一部分

我在这里得到数据:

    Future<NextPartido> getPartidoHome() async {
  var response = await http.get(baseUrl);
  if (response.statusCode == 200) {
    var body = json.decode(response.body);
    print(body);
    // JsonEncoder encoder = new JsonEncoder.withIndent('  ');
    // String prettyprint = encoder.convert(body);
    // log('movieTitle: $prettyprint');
    //
    return NextPartido.fromJson(body);
  } else {
    return throw Exception('Error getting partidohome');
  }
}

我在这里生成模型类: https : //app.quicktype.io/

response.body 是否可能不包含所有 json 数据??

以及如何获得所有 json 响应?

  If you want to have all data your model should be like this : 

  => https:// paste.of code.org / Vt6YciMmTLkirmjVYYc6Sd

  Your method could be like this :

  => Future<TestModel> getAllData() async {
  var result;
  var request = await http.get(baseUrl);

  if(request.statusCode == 200) {
    result =  testModelFromJson(request.body.toString());
  } else {
    print(request.statusCode.toString());
  }
  return result;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM