Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

arrays - Looping Through a ColdFusion Structure

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>

Here is the structure: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...