java - 为什么快速 api 没有返回 json?
问题描述
我是 webscraping 的初学者,我目前正在开发一个使用快速 api 平台来获取一些 json 的应用程序。一旦你在寻找一个特定的端点,你会得到一个代码片段,你应该粘贴到你的程序中。因此我运行了这段代码:
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class AAA {
public static void main(String args[]) throws IOException {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api-football-v1.p.rapidapi.com/v2/fixtures/league/1383/last/10?timezone=Europe%252FLondon")
.get()
.addHeader("x-rapidapi-host", "api-football-v1.p.rapidapi.com")
.addHeader("x-rapidapi-key", "myRapidAPIKey")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.toString());
}
}
但是,无论我选择什么端点,都会一遍又一遍地显示相同的NOT JSON输出:
Response{protocol=http/1.1, code=200, message=OK, url=https://api-football-v1.p.rapidapi.com/v2/predictions/157462}
我没有使用 Maven。我刚刚包含了我的代码工作所需的罐子。我究竟做错了什么?先感谢您?
解决方案
json 通常包含在响应正文中。所以你必须尝试类似的东西:
System.out.println(response.body().string());
代替
System.out.println(response.toString());
推荐阅读
- qt - QT 中的并行处理
- c# - 如何访问占位符的复选框
- python - 使用 pandas 基于来自不同数据帧的两列的数据帧过滤
- reactjs - Django REST api父子组件使用反应js表单提交,因为它是DRA?
- python - 如何在outlook中阅读来自不同帐户的电子邮件
- python-3.x - 绘制熊猫中不同行范围的补丁矩形
- wordpress - git 更改不忽略 gitignore 文件中设置的文件/文件夹
- c# - Word 和 PDF 文件中的文档属性
- sql - 如何获得每个交易品种的最低、最高和最新价格以及它在一行中出现的时间?(postgres)
- java - 如何让我的 tomcat 应用程序统计新的遗物