I'm making an android app to control my AC, in my app i would like to know the temperature outside. I have an json link to the local weather forecast provider and it have the temperature value I'm looking for.
Link to JSON (https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/16.158/lat/58.5812/data.json)
My problem is that I don't know how to get to the temperature value when it´s inside several arrays. The object I'm looking for is inside "timeSeries" -> "parameters" -> and the name is "t" and it is that "value" I want (it´s the temperature in Celsius).
I have tried several ways of fix it but obvious I'm not there :). I insert a part of my code so you can see what I'm trying.
@Override
public void onResponse(Call call, Response response) throws IOException {
String forecastData;
try {
String jsonData = response.body().string();
Log.v(TAG, jsonData);
if (response.isSuccessful()) {
forecastData = getCurrentDetails(jsonData);
}
} catch (IOException e) {
Log.e(TAG, "IO Exception caught: ", e);
} catch (JSONException e) {
Log.e(TAG, "JSON Exception caught:", e);
}
}
private String getCurrentDetails(String jsonData) throws JSONException {
JSONObject forecast = new JSONObject(jsonData);
JSONArray currently = forecast.getJSONArray("timeSeries");
String currentTemp = "";
return currentTemp;
}
});
It´s in the getCurrentDetails i want to get the temperature and then return it.