从URL获取JSON时出错

时间:2018-03-02 19:29:45

标签: android json

我想从this URL获取JSON,但它会返回此错误:

<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("598f2de43d734f86c2ccb9e868e40332");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://android.aa8.ir/getAllDataManager.php?i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

我使用此类在Android中获取JSON:

public static String getData(String Address) {
    URL url = null;
    try {
        url = new URL(Address);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("USER-AGENT", "Mozilla/5.0");
        connection.setRequestProperty("ACCEPT-LANGUAGE", "en-US,en;0.5");
        InputStream in = connection.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String line = "";
        StringBuilder responseOutput = new StringBuilder();
        while ((line = br.readLine()) != null) {
            responseOutput.append(line);
        }
        br.close();
        return responseOutput.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

我认为此错误是因为网址向我发送了Cookie或Javascript。我该如何从这个URL获得JSON?

1 个答案:

答案 0 :(得分:1)

该网址正在返回HTML。确保URL返回JSON,如果您确定URL返回JSON,那么您的错误可能在Address(错误的地址甚至是错字)。

代码似乎很好。您还可以通过从示例JSON生成器请求JSON来检查代码,例如https://www.json-generator.com/