SerializeJSON 在 ColdFusion 9 中不编码 UTF8 字符 [英] SerializeJSON doesn't encode UTF8 characters in ColdFusion 9
问题描述
我在使用 ColdFusion 和 JSON 时遇到了一些问题.我的用户有文件名和其他关键字,其中包含 ç
等字符,当我必须通过 JSON 将它们传回时,这让我很痛苦.
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.
当我对变量使用魔术 JSON 命令时:
When I use the magic JSON command on my variable:
<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' ç
?
推荐答案
您需要在 CFCONTENT 标签中指定字符集.我在没有 charset 的谷歌浏览器中尝试了这段代码,它正确地返回了文本.但是,FireFox 3.6 返回了您列出的错误字符.
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.
这会在 Chrome、FireFox 和 MSIE 中正确返回 UTF-8 字符:
This correctly returns the UTF-8 characters in Chrome, FireFox and MSIE:
<cfcontent type="application/json; charset=utf-8">
这篇关于SerializeJSON 在 ColdFusion 9 中不编码 UTF8 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!