/** * Take the String representing the complete forecast in JSON Format and pull out the data we * need to construct the Strings needed for the wireframes. * * <p>Fortunately parsing is easy: constructor takes the JSON string and converts it into an * Object hierarchy for us. */ private List<Film> getUrlsFromJson(String urlsJsonStr) throws JSONException { // These are the names of the JSON objects that need to be extracted. final String RESULTS = "results"; final String POSTER_URL = "poster_path"; final String IMAGE_URL_BASE = "http://image.tmdb.org/t/p/w185/"; List<Film> urls = new ArrayList<>(); JSONObject urlsJson = new JSONObject(urlsJsonStr); JSONArray resultsArray = urlsJson.getJSONArray(RESULTS); for (int i = 0; i < resultsArray.length(); i++) { final JSONObject result = resultsArray.getJSONObject(i); Film film = new Film(); film.posterUrl = IMAGE_URL_BASE + result.getString(POSTER_URL); film.backdropUrl = IMAGE_URL_BASE + result.getString("backdrop_path"); film.originalTitle = result.getString("original_title"); film.overview = result.getString("overview"); film.releaseDate = result.getString("release_date"); film.voteAverage = result.getString("vote_average"); urls.add(film); } return urls; }