Я хочу вывести строку на экран, говоря что-то вроде "Dublin is experiencing clouds today with a temperature of 15".
Как мне настроить таргетинг на weather.main и температуру из этого JSON и поместить его в мою строку?
Вот мой код для настройки API и возврата JSON.Я новичок в этом, поэтому любая помощь будет оценена!
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
@Path("/weather")
public class Weather {
@GET
@Path("/{param}")
public Response GetCityInfo(@PathParam("param") String city) {
String URL = "http://api.openweathermap.org/data/2.5/weather?q="+city+"&mode=JSON&APPID=cbb5da68f37d26059628449e068ce931";
Client c = ClientBuilder.newClient();
Response r = c.target(URL).request().get();
return r;
}
}
Использование Почтальона с URL http://localhost:49000/api/weather/dublin возвращает:
{
"coord": {
"lon": -6.26,
"lat": 53.35
},
"weather": [
{
"id": 803,
"main": "Clouds",
"description": "broken clouds",
"icon": "04d"
}
],
"base": "stations",
"main": {
"temp": 287.71,
"pressure": 1009,
"humidity": 82,
"temp_min": 287.15,
"temp_max": 288.15
},
"visibility": 10000,
"wind": {
"speed": 6.7,
"deg": 220
},
"clouds": {
"all": 75
},
"dt": 1539694800,
"sys": {
"type": 1,
"id": 5237,
"message": 0.0019,
"country": "IE",
"sunrise": 1539672865,
"sunset": 1539710737
},
"id": 2964574,
"name": "Dublin",
"cod": 200
}