【问题标题】:Getting driving instructions in android application using Google Directions API使用 Google Directions API 在 android 应用程序中获取驾驶说明
【发布时间】:2011-05-09 10:22:35
【问题描述】:

我有这个 android 应用程序,我应该在其中向用户显示行车路线。 我为此使用 Google Directions API。 这涉及向他们的 url 发出请求并在结果中获取 JSON。 现在,问题是:行车路线在标签/名称内 - “html-instructions”。 在这里我得到了方向,但它嵌入了 unicode 字符,例如。

"html_instructions": "沿第一个 \u003cb\u003eleft\u003c/b\u003e 前往 \u003cb\u003eBannerugatta Rd\u003c/b\u003e"

如何摆脱这些 un​​icode 值并从中获取纯文本。

请帮忙

【问题讨论】:

    标签: java android unicode driving-directions


    【解决方案1】:

    试试这样的:

    try {
        // Convert from Unicode to UTF-8
        String string = "abc\u5639\u563b";
        byte[] utf8 = string.getBytes("UTF-8");
    
        // Convert from UTF-8 to Unicode
        string = new String(utf8, "UTF-8");
    
    } catch (UnsupportedEncodingException e) {}
    

    【讨论】:

    • 感谢您的回答。实际上,在我解析后得到的实际文本中,我使用 replaceAll("\\<.>","") 删除了 HTML 标签。不过还是谢谢关心
    • 你的回答对我不起作用。 @Ankit 的 replaceAll("\\&lt;.*?&gt;",""),是的。
    【解决方案2】:

    direcObject.getString("html_instructions").replaceAll("\<.>","") 用于获取不带标签的html指令

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 2012-01-18
      相关资源
      最近更新 更多