我有以下JSON代码,我需要将其转换为结构以插入数据库
JSON
0
Object { SGID=49, SSID=9669, SEQ=1, more...}
GRADE
""
GRADEDESC
null
SEQ
1
SGID
49
SSID
9669
1
Object { SGID=50, SSID=9669, SEQ=2, more...}
GRADE
""
GRADEDESC
null
SEQ
2
SGID
50
SSID
9669
2
Object { SGID=51, SSID=9669, SEQ=3, more...}
3
Object { SGID=52, SSID=9669, SEQ=4, more...}
4
Object { SGID=53, SSID=9669, SEQ=5, more...}
5
Object { SGID=54, SSID=9669, SEQ=6, more...}
6
Object { SGID=55, SSID=9669, SEQ=7, more...}
对于简单的JSON to struct,我这样做,以下是我获取JSON对象的代码,然后我将它们转换为结构,但这次JSON很复杂,所以需要知道如何为了进入更新表,我实际上尝试了结构的转储,我得到了
结构>数组[每个元素在结构形式中有7个元素]> 结构
这是屏幕
<cfset var items= toString(getHttpRequestData().content) />
<cfset var Master = deserializeJSON(items) />
尝试这样但我被卡住了
<cfloop index="k" from="1" to="12">
<cfquery>
UPDATE table
SET
Gr = '#Trim(Evaluate("GR#k#"))#',
desc = N'#Replace(Trim(Evaluate("Desc#k#")), "'", "''", "All")#'
WHERE id = #k#
</cfquery>
</cfloop>
上面是我尝试过的,似乎不是工作的东西,我错过了我知道的东西以及我丢失的地方和内容
答案 0 :(得分:0)
看起来主要的事情是错误的
<cfqueryparam>
<cfloop index="k" from="1" to="12">
<cfquery>
UPDATE table
SET
Gr = <cfqueryparam value="#gradeRecords[k].grade.trim()#" cfsqltype="cf_sql_varchar">,
desc = <cfqueryparam value="#gradeRecords[k].gradedesc#" cfsqltype="cf_sql_varchar">
WHERE id = <cfqueryparam value="#k#" CFSQLType="CF_SQL_INTEGER">
</cfquery>
</cfloop>