Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays ColdFusion-通过数组中的嵌套结构循环_Arrays_Json_Coldfusion_Structure_Nested Loops - Fatal编程技术网

Arrays ColdFusion-通过数组中的嵌套结构循环

Arrays ColdFusion-通过数组中的嵌套结构循环,arrays,json,coldfusion,structure,nested-loops,Arrays,Json,Coldfusion,Structure,Nested Loops,我有一个从外部API返回的json: { "data" : { "consignmentDetail" : [ { "consignmentNumber" : "5995600864", "parcelNumbers" : [ "15505995600864" ] } ], "consolidated" : false, "shipmentId" : "60764454" }, "error" : null } 我

我有一个从外部API返回的json:

{ "data" : { "consignmentDetail" : [ { "consignmentNumber" : "5995600864",
            "parcelNumbers" : [ "15505995600864" ]
          } ],
      "consolidated" : false,
      "shipmentId" : "60764454"
    },
  "error" : null
}
我可以通过反序列化JSON并获取
数据.shipmentId
来获取
shipmentId
值。我确实也需要获取
委托编号
的值,但当我尝试将数组作为集合循环时,我得到了一个错误:

“无效集合 [{ParcelNumber={[15505995603009]},委托编号={5995603009}]。 必须是有效的结构或COM对象。“

到目前为止,我掌握的代码是:

<cfset consignmentDetailArray = [] >
<cfset consignmentDetailArray = shipmentData.data.consignmentDetail>
<cfset mystruct ={}>

<cfloop collection=#consignmentDetailArray# item="i">
   <cfset myStruct = consignmentDetailArray[i]>
   <cfloop collection="#myStruct#" item="key">
      <cfoutput>#key#: #myStruct[key]#<br /></cfoutput>
   </cfloop>
</cfloop>

#键:#myStruct[key]#
知道是什么导致了这个错误吗?是因为数组中有一个结构是
委托详细信息的值吗?
如果是这样,有没有关于如何正确循环该结构的指针

我或许应该补充一点,我对ColdFusion非常陌生,而且仍处于陡峭的学习曲线上:) (运行Coldfusion 10)


感谢阅读并感谢您提供的帮助。

委托DetalArray是一个数组,而不是一个结构,您使用的是cfloop collection=。您可以从1循环到len,也可以使用cfloop/array

这里有一种解决方法:

<cfloop array="#consignmentDetailArray#" index="myStruct">
  <cfloop collection="#myStruct#" item="key">
    <cfoutput>#key#: #myStruct[key]#<br /></cfoutput>
  </cfloop>
</cfloop>

#键:#myStruct[key]#

引发有关无效属性的错误。如果我这样做,它可以工作(不会出错):#key#:#myStruct[key]#
但这实际上并没有从数组内部的结构中得到任何东西,也就是说,从cfoutputwork中没有任何东西-我以为CF10有cfloop array=。。。哦哎呀,这是index=“myStruct”,不是物品。@RaymondCamden很高兴在ColdFusion上收到你的来信。我从未离开过,@Pankaj。