Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coldfusion grab data from multi level structures

Posted on 2016-08-08
3
Medium Priority
?
111 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 2000 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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

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…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

670 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