我想從URL中獲取JSON數據,並且通過瀏覽器檢查了URL,它向我顯示了有效的JSON數據,而如果我這樣做了,則出現以下錯誤:URL中的查詢中存在非法字符連接
Illegal character in query at index 47: http://bangladeshelections.org/candidate?where={
指數47是第一個大括號之後的地方。
我曾嘗試下面的代碼來獲取URL
這裏,值從上一個活動的數組。
District = value[0];
Municipality = value[1];
Type = value[2];
Ward = value[3];
url_all_products = url_all_products + "District\":\""+District+"\",\"Municipality\":\""+
Municipality+"\",\"Type\":\""+Type+"\",\"Ward\":\""+Ward+"\"}";
Log.i("Monkey", url_all_products.charAt(47) + "bulls");
new LoadAllProducts(getApplicationContext()).execute();
下面的代碼的被我用來獲得一個異步線程
URL url = new URL(url_all_products);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url_all_products));
HttpResponse response = client.execute(request);
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line="";
while ((line = in.readLine()) != null) {
sb.append(line);
break;
}
in.close();
return sb.toString();
謝謝JSON數據。
這是一個查詢字符串非法字符。 URLEncode你的查詢字符串。 – pvg
@pvg如何做?需要一些幫助... –