コード例 #1
0
  private void extractListFromJSON(String jsonStr) {

    try {
      moviesList.clear();
      JSONObject moviesJson = new JSONObject(jsonStr);
      JSONArray moviesArray = moviesJson.getJSONArray("results");

      for (int i = 0; i < moviesArray.length(); i++) {
        Movie tempMovie = new Movie();
        JSONObject jo = moviesArray.getJSONObject(i);
        tempMovie.setTitle(jo.getString(getString(R.string.ORIGIONAL_TITLE_PARAM)));
        tempMovie.setId(jo.getString(getString(R.string.ID)));
        tempMovie.setPoster_Location(jo.getString(getString(R.string.POSTER_PATH_PARAM)));
        tempMovie.setBackdrop_path(jo.getString(getString(R.string.BACKDROP_PATH_PARAM)));
        tempMovie.setOverview(jo.getString(getString(R.string.OVERVIEW_PARAM)));
        tempMovie.setRelease_Date(jo.getString(getString(R.string.RELEASE_DATE_PARAM)));
        tempMovie.setRating(jo.getString(getString(R.string.RATING_PARAM)));
        tempMovie.setPopularity(jo.getString(getString(R.string.POPULARITY_PARAM)));
        moviesList.add(tempMovie);
      }

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  private void extractMovieFromJSON(String jsonStr) {

    try {
      JSONObject jo = new JSONObject(jsonStr);

      Movie tempMovie = new Movie();
      tempMovie.setTitle(jo.getString(getString(R.string.ORIGIONAL_TITLE_PARAM)));
      tempMovie.setId(jo.getString(getString(R.string.ID)));
      tempMovie.setPoster_Location(jo.getString(getString(R.string.POSTER_PATH_PARAM)));
      tempMovie.setBackdrop_path(jo.getString(getString(R.string.BACKDROP_PATH_PARAM)));
      tempMovie.setOverview(jo.getString(getString(R.string.OVERVIEW_PARAM)));
      tempMovie.setRelease_Date(jo.getString(getString(R.string.RELEASE_DATE_PARAM)));
      tempMovie.setRating(jo.getString(getString(R.string.RATING_PARAM)));
      tempMovie.setPopularity(jo.getString(getString(R.string.POPULARITY_PARAM)));
      moviesList.add(tempMovie);

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }