Solved

Loop over deserialized json

Posted on 2013-10-28
3
1,394 Views
Last Modified: 2013-10-28
When I deserialize this:
{ "json_list": [ { "descr": "Rectangle Cold Finish LBS", "prodline": "0FC", "shape": "BAR", "sig": "ALFC" }, { "descr": "Aluminum Bar LBS", "prodline": "0FE", "shape": "BAR", "sig": "ALFE" } ] }

<cfset cfData = DeserializeJSON(theData)>

I get (I think) a struct (json_list"), and an array of structs with two structs. I need to extract the values for "prodline". How can this be accomplished?
0
Comment
Question by:kabookis
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39607583
Yes, it's an array of structures. Just loop through the array and extract the "prodline" key within the array:

<cfset cfData = DeserializeJSON(theData)>
<cfset dataArray = cfData.json_list>

<cfloop array="#dataArray#" index="elem">
      <!--- print out value for demo purposes --->
      <cfoutput>
       prodline value = #elem.prodline#  <br>
      </cfoutput>
</cfloop>
0
 

Author Closing Comment

by:kabookis
ID: 39607591
What is the record for the fastest correct response? This one has got to be up there.
I've waited longer in line at Mcdonald's.
Thanks for the help.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39607596
Haha, you're welcome ... and that's a great line closing line :)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question