json - 有没有办法在 ColdFusion 中转义井号字符 (#)?

标签 json coldfusion

我在 CFC 文件中有一个函数,它采用 JSON 字符串作为参数。然后该函数使用反序列化的数据来执行 UPDATE 查询。在 JSON 字符串中,其中一个属性的名称包含字符 #。该字符使代码在 ColdFusion 中中断,因为它被解释为变量。有没有办法让 ColdFusion “转义”该字符并将其视为字符串?请记住,这是 JSON 字符串的一部分。

下面是我的功能。由于 JSON 字符串中存在 # 字符,它不允许我访问 dnisObject。如果我从 JSON 字符串中删除那些 # ,它就可以正常工作。这些值必须使用 # 存储在数据库中,因此我不能完全删除它们。

<cffunction name="updateDnisHproduct" access="remote">
    <cfargument name = "lid" type = "numeric" required = "yes">
    <cfargument name = "updatedObj" type = "string" required="yes">


    <cfset dnisObject = DESERIALIZEJSON(arguments.updatedObj)/>

    <cfset test =[{"phone":"1001106672","lineType":"Outbound","label1":"Voicemail for line #54940","label4":"test","hcat":"18","freshStart":"0","phoneCode":"","hproduct":"3","checked":false},{"phone":"1001106672","lineType":"Outbound","label1":"Voicemail Line Box #58940","label4":"12","hcat":"54","freshStart":"0","phoneCode":"","hproduct":"12","checked":false}'>

    <cfset dnisObject = DESERIALIZEJSON(test)/>
</cffunction>

最佳答案

与通常逃避英镑符号的方式相同:将它们加倍。来自 documentation :

...To include [pound signs] in a string, double the character; for example, use ## to represent a single # character.

由于输入是字符串,所以只需执行 Replace()用两个井号代替单个井号。

关于json - 有没有办法在 ColdFusion 中转义井号字符 (#)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44037766/

相关文章:

python - 如何将 tar 文件对象转换为字符串

jquery - JSON 数据到 MVC Controller 操作结果

javascript - 通过addJavascriptInterface将JSONArray注入(inject)到webiew

php - 如果 php 数组包含值,则分配样式

coldfusion - 尝试在 ColdFusion 8/Windows Server 2003/IIS6 上使用 taffy RESTful API 框架时出现 404

java - JSON 到 JSON 转换 | Java 模板引擎

coldfusion - ColdFusion-将查询转换为CFC setter

iis - 当服务(例如 ColdFusion)关闭时,IIS 7.5 中的自定义错误页面

mysql - 有没有比使用存储过程更好的方法?

coldfusion - 使用 CFScript 编写时,提示技术之间是否存在非美学差异需要考虑?