从URL获取JSON时出错

问题描述 投票:0回答:1

我想从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 "";
}

我认为这个错误是因为URL发送给我cookie或Javascript。我如何从这个URL获得JSON?

android json
1个回答
1
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.