PDA

View Full Version : Saving grid data with coldfusion (format issue)



madirishman
2 Dec 2009, 7:31 AM
Hi All,

I'm calling a coldfusion cfc to handle my database work. I have noticed a ext JSON formatting issue and was wondering if any other coldfusion users have come across it.

If I edit multiple rows, my json returns with the square brackets, and my deserializeJSON() function will work just fine:

[{"MONTH_1":111,"MONTH_2":222,"id":28587},{"MONTH_1":1,"id":28581}]

If I only edit one row, the json returns without the square brackets and it does not parse correctly:

{"MONTH_2":111,"MONTH_3":222,"MONTH_4":333,"id":28575}

I know I could detect and add the square brackets server side, but it feels a little sloppy. Any other cf/ext people out there?

Thanks!
md

madirishman
18 Jan 2010, 12:12 PM
Anyone? I thought I had some CF pals around here! ;)

CrazyEnigma
18 Jan 2010, 3:16 PM
There are many ways to attack this. I am no CF expert, neither do I know what you are really doing.

You can do several things to alleviate the problem.

Can you not detect whether the object you receive is an Object or an array in your deserializeJSON() function? Your function should be able to accept both an Array or Object.

Or you can intercept the request and modify it to wrap the object in an Array. These seem to be the two options you have. Either way one has to give.