假设我从服务请求中获得了一些JSON,如下所示:
{
"message": "We're unable to complete your request at this time."
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么那个抄袭被编码为那个('); 我所知道的是我想解码它.
这是一种使用jQuery的方法,它突然出现在我脑海中:
function decodeHtml(html) {
return $('<div>').html(html).text();
}
Run Code Online (Sandbox Code Playgroud)
但这似乎(非常)hacky.什么是更好的方式?有"正确"的方式吗?
解析XML Feed时,我从内容标记中获取文本,如下所示:
政府已经为St Eunan学院的重大翻新项目提供资金.这是上个月宣布将其预制件替换为永久性住宿的补充.最新的补助金将允许对学校的一部分进行大规模整修,以便为课程提供新的住宿 - 该项目还将涉及屋顶维修,安装除尘系统,新的科学室配件和安装牢固的警报.Donegal代理Joe McHugh表示,学分必须归学校管理层所有
反正是否容易用例如撇号等替换这些特殊字符(即HTML实体)?
编辑:
Ti.API.info("is this real------------"+win.dataToPass)
Run Code Online (Sandbox Code Playgroud)
返回:(为了清晰起见,添加了换行符)
[INFO][TiAPI ( 5437)] Is this real------------------Police in Strabane are
warning home owners and car owners in the town to be vigilant following a recent
spate of break-ins. There has been a number of thefts from gardens and vehicles
in the Jefferson Court and Carricklynn Avenue area of the town. The PSNI have
said that residents have reported seeing a dark haired male in and around the
area …Run Code Online (Sandbox Code Playgroud)