Copy link to clipboard
Copied
Guys Im banging my head against the wall.
So Ive got JSON being returned from a cfhttp.
How the heck do I make use of that data. Everything I do gives me you get turn a complex object into a simple object.
My last line is
<cfdump var="#friendsl#"> which has this JSON from Facebook:
{
"data": [
{
"name": "whatever whatever",
"id": "554545453"
}
]
}
I've tried looping over it as a structure, nothing. Ive tried turning it into a query, nothing.
Any help would be much appreciated.
Copy link to clipboard
Copied
<cfdump var="#friendsl#"> which has this JSON
That is just a string. If you want to convert it into CF arrays/structures you need to deserialize it. See the docs on deserializeJSON
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_s_03.html
Copy link to clipboard
Copied
I left that out in my earlier post accidentally. I did deserialize, but can get it to work.
<cfset friendsl=DeserializeJSON(friends.filecontent)>
<cfdump var="#friendsl#">
I've tried
<cfset colList=ArrayToList(friendsl.data)>
<cfset colid=ListFind(colList, "id")>
<cfset colname=ListFind(colList, "name")>
<cfloop index="i" from="1" to="#ArrayLen(friendsl.DATA)#">
<h3>#friendsl.DATA[colid]#</h3>
</cfloop>
I get
Complex object types cannot be converted to simple
Copy link to clipboard
Copied
Sorry, nothing beyond the cfdump showed up in my email. I really HATE these forums...
<cfset colList=ArrayToList(friendsl.data)>
Now that I can actually +see+ your code ... the problem is the array elements are not simple strings. Each element is a structure (keys "id" and "name"). So that is why the ArrayToList conversion fails. But you do not need it anyway. Simply loop through the array and access the "id" and "name" keys directly
<cfloop index="i" from="1" to="#ArrayLen(friendsl.DATA)#">
#friendsl.DATA.id# .... #friendsl.DATA.name#
</cfloop>
Message was edited by: -==cfSearching==-
Copy link to clipboard
Copied
See my updated answer ..
jive (software)
–noun
Copy link to clipboard
Copied
Awesome! After your reply I was trying everything and was going insane lol
Yeah sometimes it hides code, kind of ironic in a forum about code!
Copy link to clipboard
Copied
Yeah sometimes it hides code, kind of ironic in a forum
about code!
Haha, true. No irony in the software name though ...