从网站获取json的问题

时间:2016-07-12 16:28:37

标签: java json url request

我试图检索位于此处的json https://challonge.com/api/tournaments/jupiter-JFC14.json?include_matches=1&include_participants=1&api_key=MY-API-KEY

(如果你想看到内容在challonge网站的开发者设置中生成api密钥,但它并不重要)

从浏览器

我没有问题,但是当我从java应用程序中执行此操作时,我得到了这个http://pastebin.com/6gkSaC4r

我使用的代码就是这个

InputStream input = null;
    OutputStream output = null;
    try {
        URL url =new URL(https://challonge.com/api/tournaments/jupiter-JFC14.json?include_matches=1&include_participants=1&api_key=MY-API-KEY);
        URLConnection con = url.openConnection();
        input = con.getInputStream();
        output = new FileOutputStream("C:/Users/giuseppe/Desktop/challonges/output2.json");
        byte[] buffer = new byte[1024];
        for (int length = 0; (length = input.read(buffer)) > 0;) {
            output.write(buffer, 0, length);
        }
    } finally {
        if (output != null) try { output.close(); } catch (IOException logOrIgnore) {}
        if (input != null) try { input.close(); } catch (IOException logOrIgnore) {}
    }

我没有这方面的经验,所以我真的不明白为什么会这样,我不知道如何进行纠正。欢迎任何帮助。

0 个答案:

没有答案