org.xml.sax.SAXParseException:解析json时出现意外的令牌

时间:2015-02-26 11:26:46

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

我正在创建一个应用程序,我正在使用谷歌地图用户可以绘制路线并获得方向一切顺利但问题是我如何从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

来解决它或以任何其他方式获取分步指导

提前致谢

1 个答案:

答案 0 :(得分:0)

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