troubleshooting Question

Ajax/Json decode for multi-dimension arrays using JQuery/JS

Avatar of brothertom
brothertom asked on
JavaScriptjQuery
6 Comments1 Solution1270 ViewsLast Modified:
I am trying to get my head around multi-dimension arrays in JQuery/JS.
From the returned JSON string (below) returned from an Ajax from JS, I need to be able to:

1. Store the top level value (e.g. 12345)
2. Then iterate through the remaining key/value pairs

So, if a simple output was required, I need:
12345
name1:value1
name2:value2
name3:value3

98765
name1:value1a
name2:value2a
name3:value3a

I have tried using the JSON.parse function but to no avail.
Could someone show me a worked example utilising JQuery/JS from the description above?

Many thanks
BT



The following array when encoded into JSON :
$arr['12345'] = array('name1' => 'value1', 'name2' => 'value2', 'name3' => 'value3');
$arr['98765'] = array('name1' => 'value1a', 'name2' => 'value2a', 'name3' => 'value3a');

gives output of
{"12345":{"name1":"value1","name2":"value2","name3":"value3"},"98765":{"name1":"value1a","name2":"value2a","name3":"value3a"}}
ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros