ColdFusion 2018 处理结构数组

ColdFusion 2018 processing an array of structs

我在处理内部数组(变体)时遇到问题。获取classjava.lang.String类型的对象不能作为数组

<cfset jsonData = deserializeJSON(httpResp.fileContent) />
    
<cfset products = jsonData.products>

<cfoutput>

    <cfloop array="#products#" index="x">   
        #x.id# - #x.handle# <br>
                    
        <cfset variants = "variants">
        
        <cfloop array="variants" index= "i">
            #i.barcode#
        </cfloop>
        
    </cfloop>    

</cfoutput>

尝试使用 cfscript

<cfscript>
jsonData = deserializeJSON(httpResp.fileContent);
    
products = jsonData.products;


for (product in products) {
   writeoutput("#product.id# - #product.handle# <br>");

   for (variant in product.variants) {
     writeoutput(variant.barcode);
   }  
}
</cfscript>

在 RRK 的帮助下(不知道如何归功于他),我能够让它发挥作用:

<cfset jsonData = deserializeJSON(httpResp.fileContent) />     
<cfset products = jsonData.products>
<cfoutput>  
    <cfloop array="#products#" index="x">   
        #x.id# - #x.handle# <br>
                    
        <cfset variants = "#x.variants#">           
        <cfloop array="#variants#" index= "i">
            <cfif IsDefined("i.barcode") and i.barcode is not "">
                #i.barcode# <br>
            </cfif>
        </cfloop>
        
    </cfloop>        
</cfoutput>