Don't Double Encode Your JSON

A friend was having an issue with some Ajax stuff today and asked me to take a look. He had a Spry JSON dataset that called a CFC that he had built specifically to retrieve data for this dataset. Since he was on 8 and rolling his own method (instead of proxying another method) he correctly set the returnFormat of the CFC to 'JSON' which ensures the proper serialization on the resultset.

The issue he found was that his result set looked like something like this:

"{\"Timestamp\":\"2007-12-20T04:22:
34.737Z\",
//and so on...

So the JSON string was being escaped. I took a look at his method and noticed that he was calling a remote service and had specified a return format of 'JSON' to the remote service. So when the function returned the string with the JSON returnFormat it was basically double encoding the string which gave him the goofy results. The fix was to specify a returnFormat of 'plain' so that the JSON string from the service was returned as is.

Just something to be mindful of with the popularity of JSON on the rise. Many public services are offering it as a return format so make sure you're only trying to serialize a coldfusion object/string when using the cffunction returnFormat.

Comments

Calendar

Sun Mon Tue Wed Thu Fri Sat
     12
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       

Subscribe

Enter your email address to subscribe to this blog.

Tags

actionscript ajax blogging cfsnippets coldfusion flash forms flex funny stuff misc model-glue off topic personal project learn slidesix sql

Recent Comments

Adding Auto Generated Code Downloads to BlogCFC
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

BlogCFC Survey #2
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

Most Difficult Captcha Of All Time
kokkooo said: [url=http://synchrophase.info/...]消費者金融 ブラック[/url] [url=http://geji-geji.com/]消費者金融ブラック[/url] [url=http... [More]

Most Difficult Captcha Of All Time
kokkooo said: <a href="http://synchrophase.info/...">消費者金融 ブラック</a> <a href="http://gej... [More]

Using A PlayStation 2 HDD In Your PC
Vodin said: Well dang. Thanks man, my uncle who owns a Video Game shop had a PS2 harddrive in the junk box, I sn... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com