1

我正在尝试开发一个快速应用程序,它将从该站点返回即将上映的电影及其删节演员:http: //developer.rottentomatoes.com/docs/read/json/v10/Upcoming_Movies。但是,我不确定如何访问最新电影以及删减的演员阵容。如果有人可以在这里帮助我,我将不胜感激,因为 JSON 对我来说有点混乱。

我使用过如何使用他们的 JSON API 从烂番茄请求电影数据?到目前为止帮助我,但我希望能够以“宿醉:布拉德利库珀等”的格式列出这部电影和演员阵容……到目前为止我所拥有的是

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
        String[] movieTitles = new String[movies.length()];
        for (int i = 0; i < movies.length(); i++)
        {
            JSONObject movie = movies.getJSONObject(i);
            movieTitles[i] = movie.getString("title");
            JSONArray cast = movie.getJSONArray("abridged_cast");
            String[] castmembers = new String[cast.length()];
            for(int j =0; j<cast.length();j++){


            }
        }

        // update the UI
        refreshMoviesList(movieTitles);
    }
    catch (JSONException e)
    {
        Log.d("Test", "Failed to parse the JSON response!");
    }
}
4

1 回答 1

1

如果我理解您的问题,您希望您的输出格式如下:矩阵:Keane Reeves,Lawrence fishburne,.....
假设您从 json 中获取正确的数据,以下将执行:

   // add each movie's title to an array
    String[] movieTitles = new String[movies.length()];
    for (int i = 0; i < movies.length(); i++)
    {
        JSONObject movie = movies.getJSONObject(i);
        movieTitles[i] = movie.getString("title") + ":";
        JSONArray cast = movie.getJSONArray("abridged_cast");
        String[] castmembers = new String[cast.length()];
        for(int j =0; j<cast.length();j++){
                movieTitles[i] += castmembers[j];
                if( j < (cast.length()-1)){
                     movieTitles[i] += ",";
                 } 
        }
    }
于 2013-06-17T01:34:31.047 回答