查询时的非法字符

Illegal character at query(查询时的非法字符)

本文介绍了查询时的非法字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个应用程序,需要查询谷歌的方向等。我最近重新组织了我的代码,做了一些优化,查询路线与路点,以削减请求发送计数。现在有个问题:我正在
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"起作用。谢谢

这篇关于查询时的非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:查询时的非法字符