我一直在尝试创建一个数据结构,但我很难过.我正在尝试创建这样的数据结构:
{
"vehicle": [
{
"inv_id": "123412",
"year": "2013",
"make": "Jeep",
"model": "Grand Cherokee"
},
{
"inv_id": "1224522",
"year": "2013",
"make": "Jeep",
"model": "Grand Cherokee"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我试过没有运气的事情.
<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>
Run Code Online (Sandbox Code Playgroud)
这是The value coldfusion.runtime.Struct cannot be converted to a number.在第一个structInsert行上抛出coldfusion错误.
有什么建议?
你不需要那个数组循环...想一想:你在循环什么?这是一个空数组.您需要做的就是将结构附加到数组:
<cfset arrayAppend( result.vehicle,{
"inventory_id" = qInv.inventory_id,
"year" = qInv.year,
"make" = qInv.make,
"model" = qInv.model
})>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
121 次 |
| 最近记录: |