Solved

Coldfusion grab data from multi level structures

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion scheduled tasks as one task 2 84
Coldfusion combining queries 15 73
Coldfusion : Unix Epoch Time 4 37
decryping the string data from visa checkout 5 28
This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

810 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