【问题标题】:org.xml.sax.SAXParseException: Unexpected token while parsing jsonorg.xml.sax.SAXParseException:解析 json 时出现意外令牌
【发布时间】:2015-02-26 11:26:45
【问题描述】:

我正在创建一个应用程序,我在其中使用谷歌地图用户可以绘制路线并获取方向一切进展顺利,但问题是我如何从 html_instruction 逐步获取方向,如下所示:

"legs" : [
        {
           "distance" : {
              "text" : "6.0 km",
              "value" : 6020
           },
           "duration" : {
              "text" : "1 hour 15 mins",
              "value" : 4514
           },
           "end_address" : "MH Road, Rawalpindi, Pakistan",
           "end_location" : {
              "lat" : 33.5955202,
              "lng" : 73.044865
           },
           "start_address" : "4th Road, Rawalpindi, Pakistan",
           "start_location" : {
              "lat" : 33.6377411,
              "lng" : 73.0647159
           },
           "steps" : [
              {
                 "distance" : {
                    "text" : "23 m",
                    "value" : 23
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 15
                 },
                 "end_location" : {
                    "lat" : 33.6375325,
                    "lng" : 73.06468649999999
                 },
                 "html_instructions" : "Head \u003cb\u003esouth\u003c/b\u003e toward \u003cb\u003e4th Rd\u003c/b\u003e",
                 "polyline" : {
                    "points" : "{zhlEom}|Lf@D@?"
                 },
                 "start_location" : {
                    "lat" : 33.6377411,
                    "lng" : 73.0647159
                 },
                 "travel_mode" : "WALKING"
              },

我正在这样做

  HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse response = httpClient.execute(httpPost, localContext);
        InputStream in = response.getEntity().getContent();
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(in);

但它的抛出异常

org.xml.sax.SAXParseException: Unexpected token (position:TEXT {

我如何解决它或使用 google mapsv2 获取逐步方向的任何其他方式

提前致谢

【问题讨论】:

标签: android json google-maps google-maps-android-api-2 map-directions


【解决方案1】:

如果 JSON 有 Unexpected token,它可能有一个未显示的不可打印字符。尝试将您的原始文本复制并粘贴到hex dump websitehere,然后与您获得的内容进行比较。

【讨论】:

    猜你喜欢
    • 2013-10-17
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    相关资源
    最近更新 更多