Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error displaying JSON Array Data - Complex object types cannot be converted to simple values

I currently have a MoocJson.json file that looks like this:

[
 {"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

My CF code is as follows:

<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 --->

When I run it, everything but the TAGS and CATEGORIES is displayed. For these two I get an error of

Complex object types cannot be converted to simple values

How do I read the TAGS and CATEGORIES arrays with in the main array?

like image 653
Kevin Bomhardt Avatar asked Apr 13 '26 19:04

Kevin Bomhardt


1 Answers

TAGS and CATEGORIES are arrays. You can use the ArrayToList function to convert them into strings.

Try this:

#ArrayToList(Course.tags)# <br>
#ArrayToList(Course.categories)# <br>
like image 92
kishore.k.vaishnav Avatar answered Apr 17 '26 18:04

kishore.k.vaishnav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!