Solved

Coldfusion grab data from multi level structures

Posted on 2016-08-08
3
42 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
  • 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now