以下是我的JSON数据:这我试图循环并获得所有关于它的每个节点的信息与关键名称和关键数据
{
"src": 1,
"feeds": [{
"id": 1,
"name": "All",
"polarPlot": true
}],
"srcFeed": 1,
"showSil": true,
"showFlg": true,
"showPic": true,
"flgH": 20,
"flgW": 85,
"acList": [{
"Id": 12589424,
"Rcvr": 1,
"HasSig": false,
"Icao": "C01970",
"Bad": false,
"Reg": "C-FJQL",
"FSeen": "/Date(1672216397120)/",
"TSecs": 334,
"CMsgs": 330,
"Alt": 34975,
"GAlt": 35206,
"InHg": 30.15059,
"AltT": 0,
"Call": "ROU1958",
"Lat": 45.59019,
"Long": -74.90746,
"PosTime": 1672216731130,
"Mlat": false,
"Tisb": false,
"Spd": 469.0,
"Trak": 59.3,
"TrkH": false,
"Type": "A321",
"Mdl": "Airbus A321 211SL",
"Man": "Airbus",
"CNum": "7117",
"From": "YYZ Lester B. Pearson, Toronto, Canada",
"To": "YQB Quebec Jean Lesage, Canada",
"Op": "Air Canada Rouge",
"OpIcao": "ROU",
"Sqk": "2222",
"Help": false,
"Vsi": 0,
"VsiT": 0,
"WTC": 2,
"Species": 1,
"Engines": "2",
"EngType": 3,
"EngMount": 0,
"Mil": false,
"Cou": "Canada",
"HasPic": false,
"Interested": false,
"FlightsCount": 2,
"Gnd": false,
"SpdTyp": 0,
"CallSus": false,
"Trt": 2,
"Year": "2016"
}, {
"Id": 12595324,
"Rcvr": 1,
"HasSig": false,
"Icao": "C0307C",
"Bad": false,
"Reg": "C-FSJJ",
"FSeen": "/Date(1672215986531)/",
"TSecs": 745,
"CMsgs": 284,
"Alt": 35000,
"GAlt": 35189,
"InHg": 30.1092529,
"AltT": 0,
"Call": "ACA394",
"Lat": 47.86931,
"Long": -72.90211,
"PosTime": 1672216731064,
"Mlat": false,
"Tisb": false,
"Spd": 513.0,
"Trak": 117.2,
"TrkH": false,
"Type": "B38M",
"Mdl": "Boeing 737MAX 8",
"Man": "Boeing",
"CNum": "61217",
"From": "YYC Calgary, Canada",
"To": "YHZ Halifax / Stanfield, Canada",
"Op": "Air Canada",
"OpIcao": "ACA",
"Sqk": "1144",
"Help": false,
"Vsi": 0,
"VsiT": 0,
"WTC": 2,
"Species": 1,
"Engines": "2",
"EngType": 3,
"EngMount": 0,
"Mil": false,
"Cou": "Canada",
"HasPic": false,
"Interested": false,
"FlightsCount": 2,
"Gnd": false,
"SpdTyp": 0,
"CallSus": false,
"Trt": 2,
"Year": "2018"
}, {
"Id": 12601386,
"Rcvr": 1,
"HasSig": false,
"Icao": "C0482A",
"Bad": false,
"Reg": "C-GBIN",
"FSeen": "/Date(1672215747131)/",
"TSecs": 984,
"CMsgs": 5124,
"Alt": 32925,
"GAlt": 33185,
"InHg": 30.1801186,
"AltT": 0,
"Call": "ROU1689",
"Lat": 45.119546,
"Long": -71.834575,
"PosTime": 1672216731191,
"Mlat": false,
"Tisb": false,
"Spd": 462.5,
"Trak": 31.1,
"TrkH": false,
"Type": "A319",
"Mdl": "Airbus A319 114",
"Man": "Airbus",
"CNum": "845",
"From": "FLL Fort Lauderdale Hollywood, United States",
"To": "YQB Quebec Jean Lesage, Canada",
"Op": "Air Canada Rouge",
"OpIcao": "ROU",
"Sqk": "1447",
"Help": false,
"Vsi": -2112,
"VsiT": 0,
"WTC": 2,
"Species": 1,
"Engines": "2",
"EngType": 3,
"EngMount": 0,
"Mil": false,
"Cou": "Canada",
"HasPic": false,
"Interested": false,
"FlightsCount": 1,
"Gnd": false,
"SpdTyp": 0,
"CallSus": false,
"Trt": 2,
"Year": "1998"
}, {
"Id": 10812570,
"Rcvr": 1,
"HasSig": false,
"Icao": "A4FC9A",
"Bad": false,
"Reg": "N420LA",
"FSeen": "/Date(1672215081608)/",
"TSecs": 1650,
"CMsgs": 4226,
"Alt": 34000,
"GAlt": 34281,
"InHg": 30.2007866,
"AltT": 0,
"Call": "LAE2512",
"Lat": 46.00371,
"Long": -71.20912,
"PosTime": 1672216731894,
"Mlat": false,
"Tisb": false,
"Spd": 399.0,
"Trak": 210.7,
"TrkH": false,
"Type": "B763",
"Mdl": "Boeing 767 316F/W",
"Man": "Boeing",
"CNum": "34627",
"Op": "MAS Air Cargo",
"OpIcao": "MAA",
"Sqk": "0706",
"Help": false,
"Vsi": 0,
"VsiT": 0,
"WTC": 3,
"Species": 1,
"Engines": "2",
"EngType": 3,
"EngMount": 0,
"Mil": false,
"Cou": "United States",
"HasPic": false,
"Interested": false,
"FlightsCount": 1,
"Gnd": false,
"SpdTyp": 0,
"CallSus": false,
"Trt": 2,
"Year": "2006"
}, {
"Id": 12706028,
"Rcvr": 1,
"HasSig": false,
"Icao": "C1E0EC",
"Bad": false,
"FSeen": "/Date(1672196473179)/",
"TSecs": 20258,
"CMsgs": 1605,
"Alt": 125300,
"GAlt": 125300,
"AltT": 0,
"Call": "TEST1234",
"Tisb": false,
"TrkH": false,
"Sqk": "",
"VsiT": 0,
"WTC": 0,
"Species": 0,
"EngType": 0,
"EngMount": 0,
"Mil": false,
"Cou": "Canada",
"HasPic": false,
"Interested": false,
"FlightsCount": 4,
"Gnd": false,
"SpdTyp": 0,
"CallSus": false,
"Trt": 1
}],
"totalAc": 5,
"lastDv": "638077811342841157",
"shtTrlSec": 30,
"stm": 1672216731909
}
我正在尝试循环并在巢状结构中拥有每个循环的数据由于依赖于平面信息,数据在嵌套循环中经常或多或少地改变我已经尝试了所有的方法,但我对冷融合知之甚少需要一些帮助,非常感谢所有人
另存为变量,然后反序列化。
<cfset JSONObject = DeserializeJSON(YourVariable)>
然后可以从它调用特定的键值,如#JSONObject.flgH#
。
如果你有多个循环,你可以输出数组符号,如#JSONObject.acList.Reg[1]#
-如果你动态循环,你可以用[i]
这样的变量替换数字。
可以这样开头:
<cfset local.stData = deserializeJSON(whatever that variable is holding the JSON) />
<!--- Now, local.stData.acList is what is called "an array of structs" --->
<cfloop array="#local.stData.acList#" index="local.n" item="local.stPlane">
<!--- In here, you can work with local.stPlane.id, for example --->
<!--- If you need to loop over the "keys" of the struct, like "Id", "Rcvr", you can do that, too. I prefer structKeyList --->
<cfloop list="#structKeyList(local.stPlane)#" index="local.sKey">
<cfif local.sKey = 'Id'>
<cfelseif local.sKey = 'Rcvr'>
</cfif>
<!--- Or... --->
<cfswitch expression="#local.sKey#">
<cfcase value="Id">
</cfcase>
<cfcase value="Rcvr">
</cfcase>
<cfdefaultcase>
<!--- For unexpected keys, or just skip this block --->
</cfdefaultcase>
</cfswitch>
</cfloop>
</cfloop>