0

我正在编写一个从 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(我打印出来)。

有没有办法定义我想要的结果数量?

我很绝望......我会很感激任何答案,即使是一个远射。

4

1 回答 1

0

页面似乎只返回 4 张图片。所以我加了start=number。因此我发送多个请求。

于 2014-05-21T08:36:37.690 回答