我在使用包装器“themoviedbapi”来抓取 TMDB 的数据时遇到了一些麻烦。
我写了一个测试类来看看,当我想把这些 json 响应放入数据库时会发生什么。
因此,当点击一个未被占用的 ID 时,我收到以下消息:
Exception in thread "main" ResponseStatus{code=34, message=The resource you requested could not be found.}
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:78)
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:45)
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:40)
at info.movito.themoviedbapi.TmdbMovies.getMovie(TmdbMovies.java:60)
at tmdb_api_to_db.Test.main(Test.java:21)
由于我的Java生锈得要命,请您告诉我,如何处理?我正在考虑 try&catch,但如果有任何好的建议,我将不胜感激!
到目前为止,这是我的代码:
package tmdb_api_to_db;
import org.apache.commons.httpclient.HttpException;
import info.movito.themoviedbapi.TmdbApi;
import info.movito.themoviedbapi.TmdbMovies;
import info.movito.themoviedbapi.model.Credits;
import info.movito.themoviedbapi.model.MovieDb;
public class Test {
public static void main(String[]args){
int movieID = 1;
try{
TmdbMovies movies = new TmdbApi("###########").getMovies();
MovieDb movie_name = movies.getMovie(movieID, "en");
Credits movie_credits = movies.getCredits(movieID);
System.out.println(movie_name);
System.out.println(movie_credits.getCast());
System.out.println(movie_credits.getCrew());
System.out.println(movie_credits.getGuestStars());
System.out.println(prettyJsonString);
}catch(XX){
}
}
}