0

Rotten Tomatoes api を使用していますが、何らかの理由で、映画監督やスタジオなどの映画に関する詳細情報を取得したい場合は、別の http ページが必要です。これは、私が映画情報を取得する URL です。この JSON から ID を取得します ("self": " http://api.rottentomatoes.com/api/public/v1.0/movies/771205893.json ")。そのIDを使用したい-その特定のURLへの別のhttp接続を作成し、各映画に関する詳細情報を取得したい. これは映画情報 JSON です。

{

"total": 591,

"movies": [{

"title": "Jack and Jill",

"year": 2011,

"runtime": "",

"release_dates": {"theater": "2011-11-11"},

"ratings": {

  "critics_score": -1,

  "audience_score": 90

},

"synopsis": "",

"posters": {

},

"abridged_cast": [

  {

    "name": "Al Pacino",

    "characters": []

  },

  {

    "name": "Adam Sandler",

    "characters": []

  },

  {

    "name": "Katie Holmes",

    "characters": []

  }

],

"links": {

  "self": "http://api.rottentomatoes.com/api/public/v1.0/movies/771205893.json",

}

}],

これは私のコードです:

        if (response != null) {
            try {
                // convert the String response to a JSON object,
                // because JSON is the response format Rotten Tomatoes uses
                JSONObject jsonResponse = new JSONObject(response);

                // fetch the array of movies in the response
                JSONArray movies = jsonResponse.getJSONArray("movies");

                // add each movie's title to an array
                movieTitles = new String[movies.length()];
                for (int i = 0; i < movies.length(); i++) {
                    JSONObject movie = movies.getJSONObject(i);
                    movieTitles[i] = movie.getString("title");
                }

                try {
                    movieId = new String[movies.length()];
                    for (int i = 0; i < movies.length(); i++) {
                        JSONObject movie = movies.getJSONObject(i);
                        movieId[i] = movie.getString("id");

                    }

movieId を取得した後、ユーザーが押したムービー ID のみを取得したいので、次を使用します。

   public void onItemClick(AdapterView<?> arg0, View arg1,
                int position, long id) {

            Intent i = new Intent(getApplicationContext(),
                    AfterClickingMovieFromInternet.class);

            i.putExtra("movieName", movieTitles[position]);
            getMovieInfo( movieId[position]);

getMovieInfo( movieId[position]) で API への 2 番目の接続を確立しようとしていますが、何らかの理由で実行されません。

4

1 に答える 1

0

2 連続接続の問題は何ですか? ライブラリをチェックしましたか?

これをお勧めします - https://github.com/kodart/Httpzoid は GSON を内部で使用し、オブジェクトを操作する API を提供します。JSON の詳細はすべて非表示になります。

Http http = HttpFactory.create(context);
http.get("http://example.com/users")
    .handler(new ResponseHandler<User[]>() {
        @Override
        public void success(User[] users, HttpResponse response) {
        }
    }).execute();
于 2013-07-14T13:01:22.627 に答える