gpt4 book ai didi

coldfusion - 阵列单元冷聚变内的结构

转载 作者:行者123 更新时间:2023-12-02 04:53:31 26 4
gpt4 key购买 nike

我一直在尝试创建一个数据结构,但遇到了困难。我正在尝试创建这样的数据结构:

{
"vehicle": [
{
"inv_id": "123412",
"year": "2013",
"make": "Jeep",
"model": "Grand Cherokee"
},
{
"inv_id": "1224522",
"year": "2013",
"make": "Jeep",
"model": "Grand Cherokee"
}
]
}

这是我试过但没有成功的方法。

<cfset result["vehicle"] = []>
<cfoutput>
<cfloop query="qinv">
#arrayAppend("result.vehicle,{})#
<cfloop array="#result.vehicle#" index="i">
#structInsert(result.vehicle[i], "inventory_id", qInv.inventory_id)#
#structInsert(result.vehicle[i], "year", qInv.year)#
#structInsert(result.vehicle[i], "make", qInv.make)#
#structInsert(result.vehicle[i], "model", qInv.model)#
</cfloop>
</cfloop>
</cfoutput>

这是抛出一个 coldfusion 错误,The value coldfusion.runtime.Struct cannot be converted to a number. 在第一个 structInsert 行。

有什么建议吗?

最佳答案

你不需要那个数组循环……想一想:你在循环什么?这是一个空数组。您需要做的就是将结构追加到数组中:

<cfset arrayAppend( result.vehicle,{
"inventory_id" = qInv.inventory_id,
"year" = qInv.year,
"make" = qInv.make,
"model" = qInv.model
})>

关于coldfusion - 阵列单元冷聚变内的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18385526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com