Google 画像から画像を要求するプログラムを作成しています。
配列に変換する JSON オブジェクトを取得します。しかし、何らかの理由で、制限のように聞こえる画像は常に 4 つしかありません。そしてそれを無効にしたい...
JSONArray results = json.getJSONObject("responseData").getJSONArray("results");
for(int j = 0; j < results.length(); j++) {
String strurl = results.getJSONObject(j).getString("unescapedUrl");
BufferedImage image = null;
try {
URL url = new URI(strurl).toURL();
System.out.println("URL content type:"+url.openConnection().getContentType());
URLConnection connection = url.openConnection();
image = ImageIO.read(connection.getInputStream());
} catch(MalformedURLException e) {
e.printStackTrace();
} catch(IOException e ) {
e.printStackTrace();
continue;
} catch (URISyntaxException e) {
e.printStackTrace();
}
// I display the image.
}
そして、results
検索キーワードが何であれ、JSONArray は常に 3 です (私はそれを印刷しました)。
必要な結果の量を定義する方法はありますか?
私は絶望的です...どんな種類の答えでも、大穴でも感謝します.