By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

json multidimensional array

P: n/a
I can't figure out how to handle multidimensional arrays with json
created with ajax/php e.g.

{"452":{"name":"chris","age":"21"},"798":{"name":" sam","qty":"22"}}

I use the following code for simple arrays but don't know how to
handle multidimensional arrays?

json_object = eval( "(" + xmlHttp.responseText + ")" );
document.getElementById('name').value= json_object["name"];

How do I get to json_object[key][name]?

Many thanks,

Chris
Oct 21 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chris <ma*********@googlemail.comwrites:
I can't figure out how to handle multidimensional arrays with json
created with ajax/php e.g.

{"452":{"name":"chris","age":"21"},"798":{"name":" sam","qty":"22"}}

I use the following code for simple arrays but don't know how to
handle multidimensional arrays?

json_object = eval( "(" + xmlHttp.responseText + ")" );
document.getElementById('name').value= json_object["name"];

How do I get to json_object[key][name]?
key = "798"

var name = json_object[key]["name"]


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Oct 21 '08 #2

P: n/a
On 21 Okt., 22:49, Chris <matchett...@googlemail.comwrote:
I can't figure out how to handle multidimensional arrays with json
created with ajax/php e.g.

{"452":{"name":"chris","age":"21"},"798":{"name":" sam","qty":"22"}}

I use the following code for simple arrays but don't know how to
handle multidimensional arrays?

json_object = eval( "(" + xmlHttp.responseText + ")" );
document.getElementById('name').value= json_object["name"];

How do I get to json_object[key][name]?

Many thanks,

Chris
Try following way:
Expand|Select|Wrap|Line Numbers
  1. json_object['452'].name
  2. json_object['452'].age
  3. ....
  4.  
Regards,
purcaholic
Oct 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.