我正在尝试使用SerializeJSON()将CFC的实例转换为字符串,我可以将其存储在数据库中,然后稍后再撤回。
我遇到的问题是使用以下代码:
<cfdump var="#THIS#">
<!--- Convert CFC to JSON --->
<cfset thisJSON = SerializeJSON(THIS)>
<cfdump var="#DeserializeJSON(thisJSON)#">
给我以下内容:
红色转储显示CFC,其中包含一个名为controls
的数组,其中包含7个项目,每个都是另一个更简单的CFC。当我运行serializeJSON
然后在将其传递回deserializeJSON
之后转储结果时,项目3 - 7变为空字符串。
这是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":""
}
}
为什么前2个项目会成功转换,但剩下的5个项目会变成字符串?
我很肯定这段代码曾经工作过,我最近升级到CF 9.0.1,还有其他人在9.0.1中遇到过JSON问题吗?
答案 0 :(得分:2)
ACF 9中的serializeJSON存在一些主要问题。确保安装了cumlative hotfix 2:
http://helpx.adobe.com/coldfusion/kb/cumulative-hot-fix-2-coldfusion-1.html
但诚实地说,serializeJSON是一个POS。我一直在使用一个名为CFJSON的旧项目,并且没有任何问题。我建议只需切换到那个并忘记serializeJSON:
答案 1 :(得分:1)
你是否已经嫁给了使用serializeJson(),或者 - 如果您所有人都在序列化一个对象 - 那么objectSave()会是更好的选择吗?