SerializeJSON不会在ColdFusion 9中编码UTF8字符 [英] SerializeJSON doesn't encode UTF8 characters in ColdFusion 9

查看:194
本文介绍了SerializeJSON不会在ColdFusion 9中编码UTF8字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些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标记中指定字符集。我在Google Chrome中尝试过此代码,但没有字符集,并且正确返回了该文本。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆