从URL获取JSON字符串

时间:2015-12-13 13:40:49

标签: java json

我试过这个

private static String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
try {
    URL url = new URL(urlString);
    reader = new BufferedReader(new InputStreamReader(url.openStream()));
    StringBuffer buffer = new StringBuffer();
    int read;
    char[] chars = new char[1024];
    while ((read = reader.read(chars)) != -1)
        buffer.append(chars, 0, read); 

    return buffer.toString();
} finally {
    if (reader != null)
        reader.close();
}
}

但它返回了

<script>
document.cookie = 'BXID=AAAAAAUo78YKTFtc33JkgZ25mtq287qQum8hFjskkvwbnF0MBw==; path=/; domain=biletix.com';
location.reload(true);
</script><noscript>Couldnot find javascript support. please enable it</noscript>

我想从http://www.biletix.com/search/TURKIYE/en#!subcat_interval:12/12/15TO19/12/15

获取对象

http://www.biletix.com/solr/en/select/?start=0&rows=100&fq=end%3A[2015-12-12T00%3A00%3A00Z%20TO%202015-12-19T00%3A00%3A00Z%2B1DAY]&sort=vote%20desc,start%20asc&&wt=json

从这里开始,我可以得到我想要的东西,但这是创建这个URL以及如何创建它的唯一方法吗?

我在Eclipse中使用此功能,但我将迁移到Android.

我找不到有关创建此网址的示例。

http://stackoverflow.com/questions/7467568/parsing-json-from-url
http://stackoverflow.com/questions/10500775/parse-json-from-httpurlconnection-object
http://en.proft.me/2013/12/5/how-parse-json-java/

但那些不行,因为我无法解析String

1 个答案:

答案 0 :(得分:0)

您获得的文本是指示浏览器的脚本

  1. 将Cookie BXID设置为AAAAAAUo78YKTFtc33JkgZ25mtq287qQum8hFjskkvwbnF0MBw。
  2. 重新加载页面。
  3. 因此,您需要通过添加Cookie标头将此Cookie添加到下一个请求中。它应该看起来像:

    Cookie: BXID=AAAAAAUo78YKTFtc33JkgZ25mtq287qQum8hFjskkvwbnF0MBw==