enter code here
このような映画サービスから JSON 応答を取得します
{
"total": 157,
"movies": [{
"id": "771205997",
"title": "Gravity",
"year": 2013,
"mpaa_rating": "PG-13",
"runtime": 91,
-------------
-------------
URL用
http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?page_limit=16&page=1&country=us&apikey=cj5a4purh8fxgcmrtn95gheu
ご覧のように、1 ページに 16 のエントリが表示されますが、157 のエントリがあるため、この URL を約 10 回実行して異なるエントリを取得する必要があり、毎回ページ パラメータを変更します。解析を開始する前にすべての応答を一度に取得する方法が Java (スレッドを使用して?) にあるかどうか疑問に思っていましたか?
これは私が使用するコードです
HttpGet httpget = new HttpGet("http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?page_limit=16&page=1&country=us&apikey=cj5a4purh8fxgcmrtn95gheu");
HttpResponse response = httpclient.execute(httpget);
// Get the response
BufferedReader rd = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
String line = "";
StringBuilder textView = new StringBuilder();
while ((line = rd.readLine()) != null) {
textView.append(line);
// System.out.println(textView);
}
String resp = textView.toString();
return resp;