Solved

Coldfusion grab data from multi level structures

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to access an read a file outside of the web root. 5 43
Comparing 2 Lists Coldfusion 8 54
ColdFusion 10 Error 2 58
Lucee & <cftransaction.... />  WITAF? 10 16
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…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

791 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