我正在尝试使用 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 问题吗?