Solved

Coldfusion grab data from multi level structures

Posted on 2016-08-08
3
83 Views
Last Modified: 2016-08-08
Hello experts.
I need help to get data from deserializeJSON string with multi level structures.
example code:
<cfset responseString = '{"Test1":{"map":{"id":"1","label":"Test1"},"sortOrder":1},"Test2":{"map":{"id":"2","label":"Test2"},"sortOrder":21}}'>
<cfset responseString = deserializeJSON(responseString)>
<cfdump var="#responseString#">
Using cfloop i want to insert the id ,label and sortorder for each item (Test1 ,Test2)
Any help?
0
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41747670
Loop through the top level keys and extract the substructure. Then grab the value of the relevant keys: id, label, sortOrder.

<cfset responseString = '{"Test1":{"map":{"id":"1","label":"Test1"},"sortOrder":1},"Test2":{"map":{"id":"2","label":"Test2"},"sortOrder":21}}'>

<cfset response = deserializeJSON(responseString)>

<cfloop collection="#response#" item="key">
	<!--- extract current structure --->
	<cfset item = response[key]>

	<!--- DEMO: Display id, label and sort order --->
	<cfoutput>
	id : #item.map.id# 
	label : #item.map.label# 
	order : #item.sortOrder# 
	</cfoutput>
	<br>
</cfloop>

Open in new window

0
 
LVL 2

Author Comment

by:Panos
ID: 41747733
Hi agx.
Thank you again  for your great help.
I think that you have covert in the last three question a lot of the deserializeJSON structure and array output stuff.
Many thanks
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41748069
Glad I could help :)
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

738 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