gpt4 book ai didi

android - 如何从 Rotten Tomatoes 的 API 访问特定的 JSON 数据

转载 作者:行者123 更新时间:2023-11-30 03:33:00 25 4
gpt4 key购买 nike

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

我用过How to request movie data from Rotten Tomatoes using their 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!");
}
}

最佳答案

如果我理解你的问题,你希望你的输出格式如下: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] += ",";
}
}
}

关于android - 如何从 Rotten Tomatoes 的 API 访问特定的 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17139224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com