我正在尝试开发一个快速的应用程序,它将从这个网站返回即将上映的电影及其精简演员:http://developer.rottentomatoes.com/docs/read/json/v10/Upcoming_Movies。但是,我不确定如何访问最新的电影以及删节演员。如果有人可以帮助我,我会非常感激,因为JSON对我来说有点困惑。
到目前为止,我已经使用How to request movie data from Rotten Tomatoes using their JSON API?来帮助我,但我希望能够以“The Hangover:Bradley Cooper等”的格式列出电影和演员阵容。到目前为止是这个
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!");
}
}
答案 0 :(得分:1)
如果我理解你的问题,你希望你的输出格式如下:Matrix: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] += ",";
}
}
}