【问题标题】:Decode HTML Escape Characters [duplicate]解码 HTML 转义字符 [重复]
【发布时间】:2016-05-02 04:02:31
【问题描述】:

我正在从 Google Directions API 下载 JSON。对于 HTML_Instructions 字段,代表导航所需的实际指令,格式如下:

"Head \u003cb\u003esoutheast\u003c/b\u003e on \u003cb\u003eMinor Ave\u003c/b\u003e toward \u003cb\u003eMadison St\u003c/b\u003e",

有没有办法从 Java/Android 应用程序中下载的字符串中解码/删除转义字符。

感谢您的帮助。

【问题讨论】:

    标签: java android html json google-api


    【解决方案1】:

    在Java中使用

    String result = java.net.URLDecoder.decode(url, "UTF-8");
    

    在 JS 中使用decodeURIComponent

    document.write(decodeURIComponent("Head \u003cb\u003esoutheast\u003c/b\u003e on \u003cb\u003eMinor Ave\u003c/b\u003e toward \u003cb\u003eMadison St\u003c/b\u003e"))

    【讨论】:

    • 这是 Java 中可用的方法/类,而不是 Javascript?
    • 我应该使用 URLDecoder 吗?
    • 哎呀,是的。我错过了 JAVA 标签
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 2012-11-27
    • 1970-01-01
    相关资源
    最近更新 更多