gpt4 book ai didi

java - 查询时出现非法字符

转载 作者:行者123 更新时间:2023-12-01 14:03:34 27 4
gpt4 key购买 nike


我有一个应用程序需要向 Google 查询方向等。我最近重新组织了我的代码,做了一些优化来查询带有路点的路线,以减少请求发送计数。现在有一个问题:我得到了

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”有效。谢谢

关于java - 查询时出现非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19126708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com