0
我正在学习Java和SpringBoot。试图制作一个网络应用程序来检查天气。我正在使用来自https://openweathermap.org/api的API。初学者 - Springboot天气计划
我不知道如何从API(JSON)检索数据。有人能告诉我什么吗?
public String connectAndResponse(String url) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getResponseCode()==200 ? connection.getInputStream() : connection.getErrorStream()
));
String line = "";
while((line = reader.readLine()) !=null){
stringBuilder.append(line);
}
return stringBuilder.toString();
}
我已经处理JSON在一根绳子上,但我不知道如何使用JSON使用弹簧启动(它会在语言环境中输入窗体上工作)。