public ArrayList<MovieVideo> processJSON(JSONObject json) throws JSONException { JSONArray jsonArray = json.getJSONArray("results"); ArrayList<MovieVideo> movieVideos = new ArrayList<MovieVideo>(); for (int index = 0; index < jsonArray.length(); index++) { JSONObject object = jsonArray.getJSONObject(index); MovieVideo movieVideo = new MovieVideo(); String site = object.getString("site"); String key = object.getString("key"); String[] videoUrls = Utils.getVideoUrls(key, site); movieVideo.setId(object.getString("id")); movieVideo.setName(object.getString("name")); movieVideo.setImageUrl(videoUrls[0]); movieVideo.setVideoUrl(videoUrls[1]); movieVideos.add(movieVideo); } return movieVideos; }
@Override protected ArrayList<MovieVideo> doInBackground(String... urls) { try { Log.d(this.getClass().getName(), "about to run this"); return processJSON(Utils.fetchData(urls[0])); } catch (IOException e) { Log.d(TAG, "Something went wrong.", e); } catch (JSONException e) { Log.e(TAG, "Something went wrong processing the json: ", e); } return null; }