Created
February 17, 2015 21:17
-
-
Save victoraguilarc/f052e75e6a6d30402ef1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.json.JSONArray; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| public class WeatherDataParser { | |
| /** | |
| * Given a string of the form returned by the api call: | |
| * http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7 | |
| * retrieve the maximum temperature for the day indicated by dayIndex | |
| * (Note: 0-indexed, so 0 would refer to the first day). | |
| */ | |
| public static double getMaxTemperatureForDay(String weatherJsonStr, int dayIndex) | |
| throws JSONException { | |
| // TODO: add parsing code here | |
| JSONObject weather = new JSONObject(weatherJsonStr); | |
| JSONArray list = weather.getJSONArray("list"); | |
| JSONObject day = list.getJSONObject(dayIndex); | |
| JSONObject dayTemp = day.getJSONObject("temp"); | |
| double max = dayTemp.getDouble("max"); | |
| return max; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment