gpt4 book ai didi

json - 显示 JSON 数组数据时出错 - 无法将复杂对象类型转换为简单值

转载 作者:行者123 更新时间:2023-12-01 13:45:57 25 4
gpt4 key购买 nike

我目前有一个如下所示的 MoocJson.json 文件:

[
{"body":"some text goes here",
"link":"a link is here",
"name":"name of product goes here",
"language":"language goes here",
"tags":["tag1","tag2","tag3","tag4"],
"initiative":"initiative content goes here",
"start_date":"start date goes here",
"categories":["cat1","cat2","cat3"]
},
{"body":"2 some text goes here",
"link":"2 a link is here",
"name":"2 name of product goes here",
"language":"2 language goes here",
"tags":["2 tag1","2 tag2","2 tag3","2 tag4"],
"initiative":"2 initiative content goes here",
"start_date":"2 start date goes here",
"categories":["2 cat1","2 cat2","2 cat3"]
},
{"body":"3 some text goes here",
"link":"3 a link is here",
"name":"3 name of product goes here",
"language":"3 language goes here",
"tags":["3 tag1","3 tag2"],
"initiative":"2 initiative content goes here",
"start_date":"2 start date goes here",
"categories":["3 cat1"]
}
]
// End of JSON file

我的CF代码如下:

<cffile action="read" file="#ExpandPath("./MoocJson.json")#" variable="myxml">
<cfset mydoc = deserializedJSON(myxml)>
<cfdump var="#mydoc#"> <!--- this dumps out the JSON in Array format --->

<cfoutput> My Doc Length = #arraylen(mydoc)#</cfoutput>

<!--- Loop through Array of mydoc and out put content --->
<cfoutput>
<cfloop from="1" to="#arrayLen(mydoc)#" index="i">
<cfset Course = mydoc[i]>

#Course.Name# <br>
#Course.body# <br>
#Course.language# <br>
#Course.link# <br>
#Course.initiative# <br>
#Course.start_date# <br>
#Course.tags# <br>
#Course.categories# <br>

</cfloop>
</cfoutput>
<!--- End of Code --->

当我运行它时,除了 TAGS 和 CATEGORIES 之外的所有内容都会显示。对于这两个,我得到一个错误

Complex object types cannot be converted to simple values

如何读取主数组中的 TAGS 和 CATEGORIES 数组?

最佳答案

TAGS 和 CATEGORIES 是数组。您可以使用 ArrayToList函数将它们转换成字符串。

试试这个:

#ArrayToList(Course.tags)# <br>
#ArrayToList(Course.categories)# <br>

关于json - 显示 JSON 数组数据时出错 - 无法将复杂对象类型转换为简单值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36204055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com