读取JSON时出现问题

时间:2019-02-27 15:35:45

标签: java json apache-commons

我正在尝试从公司的内部网络读取JSON,我已配置

  System.setProperty("java.net.useSystemProxies", "true");
or
  System.setProperty("https.proxyHost", "XX.XX.XX.XX");
  System.setProperty("https.proxyPort", "XXXX");

我可以在互联网上公开阅读该API,而不会遇到任何问题

但是,当读取我公司的API而不是JSON时,它将返回HTML表

json = (java.lang.String) "<table border="0" cellpadding="4" cellspacing="0">
<thead>
<tr>
<th>status</th><th>message_code</th><th>devices</th><th>message</th></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>SUCCESS</td><td>Array</td><td>Success</td></tr>
</tbody>
</table>

我用过

String json = IOUtils.toString(url, Charset.forName("UTF-8"));

  URLConnection yc = oracle.openConnection();
   BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));

我使用此代码解决了问题

URL url = new URL(sURL);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");
            BufferedReader br = new BufferedReader(new InputStreamReader(
            (conn.getInputStream())));

0 个答案:

没有答案