SerializeJSON does not encode UTF8 characters in ColdFusion 9

I'm having problems with ColdFusion and JSON. My users have file names and other keywords with characters such as ç in them, which hurts me when I have to pass them through JSON.

When I use the magic JSON command for 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 who spits out is that that doesn't help anyone.

Is there anything I can do to save my users ç ?

+8
json coldfusion coldfusion-9
source share
2 answers

You need to specify the character set in the CFCONTENT tag. I tried this code in Google Chrome without a charset and it returned the text correctly. However, FireFox 3.6 returned the invalid characters you specified.

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

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

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

0
source share

All Articles