android中的URISyntaxException

时间:2012-05-10 16:14:51

标签: android

我有一个问题,我想解析一个带有JSON数据的URL。当我想从该URL获取数据时,它显示URISyntaxException,但是相同的URL在浏览器上运行得非常好。我不知道为什么它在浏览器上运行时会返回相同的错误。请建议我任何解决方案。

logcat的:

05-10 21:26:21.465: W/System.err(379): java.net.URISyntaxException: Illegal character in query at index 159: http://apibeta.highgearmedia.com/v1/vehicles/get-make-models.json?sort=mpg&to=&filter=category&client-id=10030812&from=coupe&signature=pqSBdOzE5-bgUf1V61UGFQ==
05-10 21:26:21.475: W/System.err(379):  at java.net.URI.validateQuery(URI.java:434)
05-10 21:26:21.475: W/System.err(379):  at java.net.URI.parseURI(URI.java:340)
05-10 21:26:21.475: W/System.err(379):  at java.net.URI.<init>(URI.java:72)
05-10 21:26:21.486: W/System.err(379):  at com.TCC.android.ResearchList.getJsonSring(ResearchList.java:3891)
05-10 21:26:21.486: W/System.err(379):  at com.TCC.android.ResearchList$67.run(ResearchList.java:4069)
05-10 21:26:23.004: W/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406b8b78

代码:

HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(url));//===> This line returns an error
            HttpResponse response = client.execute(request);
            InputStream ips = response.getEntity().getContent();
            BufferedReader buf = new BufferedReader(new InputStreamReader(ips,
                    "UTF-8"));

            StringBuilder sb = new StringBuilder();
            String s;
            while (true) {
                s = buf.readLine();
                if (s == null || s.length() == 0)
                    break;
                sb.append(s);

            }
            buf.close();
            ips.close();
            return sb.toString();

提前致谢。

0 个答案:

没有答案