• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to display data from JSON

Participant ,
Jun 10, 2011 Jun 10, 2011

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.

TOPICS
Advanced techniques

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 10, 2011 Jun 10, 2011

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 10, 2011 Jun 10, 2011

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 10, 2011 Jun 10, 2011

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 10, 2011 Jun 10, 2011

Copy link to clipboard

Copied

See my updated answer ..

jive (software)

     –noun

    1.  Slang . deceptive, exaggerated, or meaningless talk: Don't give me any of that jive!
     –verb (used with object)
     2.  Slang . to tease; fool; kid: Stop jiving me that this is real software!
    

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 10, 2011 Jun 10, 2011

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 11, 2011 Jun 11, 2011

Copy link to clipboard

Copied

LATEST

Yeah sometimes it hides code, kind of ironic in a forum

about code!

Haha, true. No irony in the software name though ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation