从 struct 中的 struct 中提取 JSON 数据

Extract JSON data from struct in struct

查看 deserializeJSON(查询)的输出。

对于每一行,我如何才能只提取 id 和 DTIME?以下是我的代码:

 <cfscript>
  record=deserializeJSON(query_testing.data_test);

  writeDump(record);

</cfscript>

下面是 "query_testing.data_test" 中的示例数据:

 '{"id3":
        {"DECISION":1,
        "DTIME":"2013-10-18 16:17:28"},
   "id5":
        {"DECISION":1,
        "DTIME":"2013-10-09 15:43:35",}
  }'
<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>