【发布时间】:2015-01-23 11:08:07
【问题描述】:
我在做什么: 我正在尝试在 android 中进行反向地理编码
我收到以下错误:: java.lang.IllegalArgumentException:索引 59 处查询中的非法字符:http://maps.google.com/maps/api/geocode/json?address=Agram,班加罗尔,卡纳塔克邦,印度&sensor=false
注意:该请求在浏览器中获得 json 响应,但不是来自我下面的班级
这一行给出了这个错误::
HttpGet httpget = new HttpGet(url);
JSONfunctions.java
public class JSONfunctions {
public static JSONObject getJSONfromURL(String url) {
InputStream is = null;
String result = "";
JSONObject jArray = null;
// Download JSON data from URL
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
// Convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return jArray;
}
}
【问题讨论】:
-
考虑对您的 URL 参数值进行 URL 编码。
-
@laalto ...您能否作为答案显示,我是新来提出编码请求的!
-
Java URL encoding的可能重复
标签: java android json google-maps