小编典典

SerializeJSON在ColdFusion 9中不编码UTF8字符

json

我在ColdFusion和JSON方面遇到一些问题。我的用户的文件名和其他关键字带有类似字符的字符ç,当我不得不通过JSON将其传递回时,这让我很痛苦。

当我在变量上使用magic JSON命令时:

<cfcontent type="application/json"> 
<cfset variables.stGalleryItem = StructNew() />
<cfset variables.stGalleryItem["imagePath"] = siteRoot & '/images/350460/hellç.txt' />
<cfset variables.stGalleryItem["title"] = 'çççç'  />
<cfset variables.stGalleryItem["author"] = 'HI' />
<cfset variables.stGalleryItem["text"] = 'aa' />
<cfset ArrayAppend(variables.arrGallery,variables.stGalleryItem) />

<cfoutput>
  #Trim(SerializeJSON(variables.arrGallery))#
</cfoutput>

被吐出来的角色是 ,这对任何人都没有好处。

我有什么办法可以保护用户的权益ç


阅读 229

收藏
2020-07-27

共1个答案

小编典典

您需要在CFCONTENT标记中指定字符集。我在没有 字符集的 Google
Chrome浏览器中尝试了此代码,并正确返回了文本。但是,FireFox 3.6返回了您列出的错误字符。

这会在Chrome,FireFox和MSIE中正确返回UTF-8字符:

<cfcontent type="application/json; charset=utf-8">
2020-07-27