请参阅deserializeJSON(查询)的输出。
对于每一行,我如何只提取id和DTIME?以下是我的代码:
'{"id3":
{"DECISION":1,
"DTIME":"2013-10-18 16:17:28"},
"id5":
{"DECISION":1,
"DTIME":"2013-10-09 15:43:35",}
}'
以下是“query_testing.data_test”中的示例数据:
2-dimensional
答案 0 :(得分:3)
<cfscript>
record = deserializeJSON(query_testing.data_test);
rows = [];
for (id in record) {
rows.add({
id: reReplace(id, "^id", ""),
dtime: record[id].DTIME
});
}
writeDump(rows);
</cfscript>
这是标签变体和请求的用法示例:
<cfset record = deserializeJSON(query_testing.data_test)>
<cfset rows = []>
<cfloop collection="#record#" item="id">
<cfset rows.add({
id: reReplace(id, "^id", ""),
dtime: record[id].DTIME
})>
</cfloop>
<cfdump var="#rows#">
<!--- print as table --->
<cfoutput>
<table>
<tr>
<th>id</th>
<th>dtime</th>
</tr>
<cfloop array="#rows#" index="row">
<tr>
<td>#encodeForHtml(row.id)#</td>
<td>#dateTimeFormat(row.dtime, "yyyy-mm-dd, HH:nn:ss")#</td>
</tr>
</cfloop>
</table>
</cfoutput>