SerializeJSON不在ColdFusion 9中编码UTF8字符

时间:2021-02-03 10:04:22

I'm having some issues with ColdFusion and JSON. My users have filenames and other key words with characters like ç in them which is causing me a pain when I have to pass them back via JSON.

我有一些ColdFusion和JSON的问题。我的用户有文件名和其他关键字,其中包含c等字符,当我必须通过JSON将它们传回时,这让我很痛苦。

When I use the magic JSON command on my variable:

当我对变量使用神奇的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>

The character that gets spit out is �, which does no one any good.

这个角色让吐出�,没有好处。

Is there anything I can do to preserve my users' ç?

我能做些什么来保护我的用户c ?

2 个解决方案

#1


8  

You need to specify the Character Set in your CFCONTENT tag. I tried this code in Google Chrome without charset and it returned the text correctly. However, FireFox 3.6 returned the incorrect characters you listed.

您需要在CFCONTENT标记中指定字符集。我在谷歌Chrome中尝试了这段代码,没有使用字符集,并且正确地返回了文本。然而,FireFox 3.6返回了你列出的错误字符。

This correctly returns the UTF-8 characters in Chrome, FireFox and MSIE:

它正确地返回了Chrome、FireFox和MSIE中的UTF-8字符:

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

#2


0  

Do the conversion yourself : http://tojson.riaforge.org/ (native) or http://json-lib.sourceforge.net/ (via a Java library)

自己进行转换:http://tojson.riaforge.org/(本机)或http://json-lib.sourceforge.net/(通过Java库)

#1


8  

You need to specify the Character Set in your CFCONTENT tag. I tried this code in Google Chrome without charset and it returned the text correctly. However, FireFox 3.6 returned the incorrect characters you listed.

您需要在CFCONTENT标记中指定字符集。我在谷歌Chrome中尝试了这段代码,没有使用字符集,并且正确地返回了文本。然而,FireFox 3.6返回了你列出的错误字符。

This correctly returns the UTF-8 characters in Chrome, FireFox and MSIE:

它正确地返回了Chrome、FireFox和MSIE中的UTF-8字符:

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

#2


0  

Do the conversion yourself : http://tojson.riaforge.org/ (native) or http://json-lib.sourceforge.net/ (via a Java library)

自己进行转换:http://tojson.riaforge.org/(本机)或http://json-lib.sourceforge.net/(通过Java库)