如何用我的cfoutput返回结构? [英] How to return in struct with my cfoutput?
问题描述
我正在尝试输出某些键值以显示(我已经准备好了)。但是由于某种原因,它作为结构返回。基本上,我正在从查询语句转换为api调用。但是由于某些原因,我无法从 cfoutput
返回它,以显示为api调用或json文件中的结构。谁能告诉我我做错了什么。谢谢您的帮助。这是我的代码:
I am trying to output certain key values to show(WHICH I AM GETTING ALREADY). But for some reason it is returning as a struct. Basically, I am converting from query statement into api call. But for some reason I cant get it return from cfoutput
to show as a struct from the api call or a json file. Can anyone tell me what I have done wrong. thanks for the help. here is my code:
输出:我将所有json字段显示在一个结构中。 (未注释 cfscript
)
Output: I get all my json fields showing in a struct. (with cfscript
uncommented out)
用当前代码更新输出:(我得到了某些输出关键值,但是我可以遍历一个循环,我知道我拥有的方法不是最好的方法)
<cfset jsonDatas = fileRead("c:\Users\Desktop\myApi.json" )>
<cfset jsonData = deserializeJSON(jsonDatas) />
<cfdump var="#jsonData#" abort="true">
<cfloop array="#jsonData#" index="prop">
<cfoutput>
<br>Output:
#prop.employeeId#
.....
</cfoutput>
</cfloop>
我的Json:
[
{
"employeeId" : "77777",
"lastName" : "DOE",
"firstName" : "JOHN",
"middleName" : null,
"sex" : "Male",
"jobStatus" : "Active",
"jobStatusDate" : "2020-01 03 00:00:00.0",
"departmentNbr" : "5555",
}
]
推荐答案
让我们看看第三次尝试是否能解决问题。
Let's see if the third try does the trick.
我添加了更多数据,以便我们可以看到每个数组
I added more data so that we can see that each array is processed separately.
<cfscript>
json =
'[
{
"employeeId" : "77777",
"lastName" : "DOE",
"firstName" : "JOHN",
"middleName" : null,
"sex" : "Male",
"jobStatus" : "Active",
"jobStatusDate" : "2020-01 03 00:00:00.0",
"departmentNbr" : "5555"
},
{
"employeeId" : "123",
"lastName" : "Doe",
"firstName" : "Jane",
"middleName" : "H",
"sex" : "Female",
"jobStatus" : "Active",
"jobStatusDate" : "2021-01 03 00:00:00.0",
"departmentNbr" : "14"
}
]';
jsonData = DeserializeJSON(json);
writedump(jsonData);
for (row in jsonData) {
writeoutput("<hr />");
for (item in row) {
writeoutput(item & ": " & row[item] & "<br />");
}
}
</cfscript>
或从文件
<cfscript>
jsonDatas = fileRead("c:\Users\Desktop\myApi.json" );
jsonData = deserializeJSON(jsonDatas);
writedump(jsonData);
for (row in jsonData) {
writeoutput("<hr />");
for (item in row) {
writeoutput(item & ": " & row[item] & "<br />");
}
}
</cfscript>
这篇关于如何用我的cfoutput返回结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!