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

cfunited08

Calendar

Sun Mon Tue Wed Thu Fri Sat
    123
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 misc model-glue off topic personal project learn slidesix sql

Recent Comments

ColdFusion/Sharepoint Integration - Part 1 - Authenticating
Steve Hammonds said: Yes, I restarted CF. Typing into my browser works fine too except: From my desktop I do not have to... [More]

MySQL Error Code 17?
Gerald said: Repair the table. [More]

T-SQL Dealing with Null Values in an Order By Clause
andrew said: uh, jas, yeah it does. notice that "rank" on the end of the order by clause? that handles ... [More]

T-SQL Dealing with Null Values in an Order By Clause
Jas said: I don't think tim's solution will do exactly what the OP wanted. It's assigning a rank of 0 to all t... [More]

Chinese Birth Calendar Accuracy Test
Ashton said: It was right for my first son and I am using it as a guide to conceive a girl next time. It just giv... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com