我正在使用烂番茄 api,出于某种原因,如果我想获得有关电影导演或工作室等电影的更多信息,我需要另一个 http 页面。这是我获取电影信息的网址。从这个 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 建立第二个连接,但由于某种原因它不会执行.....如果有人知道我很高兴知道!