I'm trying to use SerializeJSON() to turn an instance of CFC into a string, whcih I can store in a database and then pull back out again later on.
The problem I'm having is using the following code:
<cfdump var="#THIS#">
<!--- Convert CFC to JSON --->
<cfset thisJSON = SerializeJSON(THIS)>
<cfdump var="#DeserializeJSON(thisJSON)#">
Gives me the following:
The red dump shows the CFC, with an array called controls
with 7 items in it, each is another simpler CFC. When I run serializeJSON
and then dump the result of that after passing it back through deserializeJSON
, items 3 - 7 have become empty strings.
Here's the JSON:
{
"MESSAGE":"",
"CONTROLS":
[
{
"INDEX":"1.0",
"NAME":"maxP11D",
"SELWHERE":"",
"DEF":"7940.0",
"MMD":true,
"ORDER":"7",
"APP":"",
"PRE":"",
"MAXCAP":"35946.0",
"FORMAT":"pound",
"VALUE":"",
"DESC":"List price exc FRF & VED",
"MINCAP":"7939.0",
"MINVAL":"7939.0",
"MAXVAL":"35946.0",
"TYPE":"range",
"TITLE":"P11D"
},
{
"INDEX":"2.0",
"NAME":"Y13Taxat22",
"SELWHERE":"",
"DEF":"0.0",
"MMD":true,
"ORDER":"6",
"APP":" pa",
"PRE":"Tax at 20%",
"MAXCAP":"1904.1099853515625",
"FORMAT":"pound",
"DESC":"Personal tax rate",
"VALUE":"",
"MINVAL":"0",
"MINCAP":"0.0",
"MAXVAL":"1904.1099853515625",
"TYPE":"range",
"TITLE":"Company car tax"
},
"",
"",
"",
"",
""
],
"SELECTRESTRICT":"
(taxtype<6)AND (t.Make=@Peugeot@)\r\nAND t.model NOT LIKE @%407%@\r\nAND
t.model NOT LIKE @% old@\r\nAND t.model != @107 3 door@\r\nAND
t.model != @107 5 door@\r\nORDER BY \r\nt.model = @%iOn%@
DESC,\r\nt.model = @107 3 door New@ DESC,\r\nt.model = @107 5 door New@
DESC,\r\nt.model LIKE @%207%@ DESC,\r\nt.model LIKE @%RCZ%@
DESC,\r\nt.model LIKE @%308%@ DESC,\r\nt.model LIKE @%3008%@
DESC,\r\nt.model LIKE @%4007%@ DESC,\r\nt.model = @508 Saloon@
DESC,\r\nt.model = @508 SW@ DESC,\r\nt.model = @508 RXH@
DESC,\r\nt.model LIKE @%5008%@ DESC,\r\nt.model LIKE @%807%@
DESC,\r\nt.model LIKE @%Bipper%@ DESC,\r\nt.model LIKE @%Partner%@
DESC,\r\nt.model ASC
",
"SHOWNOTES":true,
"MYSQL": {
"WHERE":"",
"COLS":"
t.maxP11D, t.Y13Taxat22, t.Y13Taxat40, t.CO2gpkm,
t.fuelConsumptionDf, t.bodyStyle, t.fuelType,
",
"EXCLUDE":""
}
}
Why would the first 2 items convert successfully but the remaining 5 change into strings?
I'm positive this code used to work, I have very recently upgraded to CF 9.0.1, has anyone else had a problem with JSON in 9.0.1?
there are some major problem with serializeJSON in ACF 9. Make sure that you have cumlative hot fix 2 installed:
http://helpx.adobe.com/coldfusion/kb/cumulative-hot-fix-2-coldfusion-1.html
In all honesty though, serializeJSON is a POS. I've been using an old project called CFJSON and haven't has any issues with it. I would suggest just switching over to that and forget about serializeJSON: