Reputation: 31
Can someone help me loop through a structure.
<cfset resData2 = ConvertXmlToStruct(gatewayResponse.Filecontent, StructNew())>
<cfset resTran2 = 'resData2.Body.PosResponse.Ver1.0.Transaction.ReportBatchDetail.Details'>
<cfloop index="idx2" from="1" to=#StructCount(resTran2)# step="1">
<cfdump var="#resTran2#">
</cfloop>
Upvotes: 2
Views: 363
Reputation: 1228
A few issues with your code. As @Miguel-F pointed out, your assignment to restran2
should not be enclosed in quotes because you're making the assignment into a literal string. Secondly, your result going into resTran2
is an array of structs, so what you want to use for your upper loop limit is ArrayLen()
and not StructCount()
. Lastly, because one of your keys Ver1.0
contains a period in it, you will need to use bracket notation instead of dot notation to reference it.
<cfset resData2 = ConvertXmlToStruct(gatewayResponse.Filecontent, StructNew())>
<cfset resTran2 = resData2["Body"]["PosResponse"]["Ver1.0"]["Transaction"]["ReportBatchDetail"]["Details"]>
<cfloop index="idx2" from="1" to="#ArrayLen(resTran2)#" step="1">
<cfset batchID = resTran2["batchID"][idx2]>
<cfset batchSeqNbr = resTran2["batchSeqNbr"][idx2]>
....
</cfloop>
Upvotes: 3