本文介紹了查詢時的非法字符的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個應用程序,需要查詢谷歌的方向等。我最近重新組織了我的代碼,做了一些優(yōu)化,查詢路線與路點,以削減請求發(fā)送計數。現在有個問題:我正在
java.lang.IllegalArgumentException: Illegal character in query at index 146: http://maps.googleapis.com/maps/api/directions/json?origin=52.4000826,16.8928842&destination=52.4129715,16.8296386&waypoints=52.4053469,16.8969666|52.4049754,16.8811389&sensor=false
我相信索引146處字符是‘|’。該字符有什么問題?
謝謝您的建議。
這是我用于生成查詢的代碼:
try {
String requestString = "http://maps.googleapis.com/maps/api/directions/"
+ "json?origin="
+ Double.toString(start.getLatitude())
+ ","
+ Double.toString(start.getLongitude())
+ "&destination="
+ Double.toString(end.getLatitude())
+ "," + Double.toString(end.getLongitude());
if (points.length > 2) {
String waypoints = "&waypoints="
+ Double.toString(points[1].getLatitude()) + ","
+ Double.toString(points[1].getLongitude());
for (int i = 2; i < points.length - 1; i++) {
waypoints = waypoints + "|"
+ Double.toString(points[i].getLatitude())
+ ","
+ Double.toString(points[i].getLongitude());
}
requestString = requestString + waypoints;
}
requestString = requestString + "&sensor=false";
推薦答案
UFL1138是對的。將”|”替換為”%7C”起作用。謝謝
這篇關于查詢時的非法字符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,