javascript - Parse an Array from JSON where each field key is a number -


what need is, given json like

{   "1" : "a",   "7" : "something"   "3" : {       "1" : "blah"   } } 

convert these array (say x).

x[1] = "a" x[7] = "something" x[3] = y (where y[1] = "blah") 

you'll need deserialize json non-array object graph, , copy properties arrays. i'm not aware of shortcut it.

the basic loop once you've deserialized json obj roughly:

var ar; var key;  ar = []; (key in obj) {     if (obj.hasownproperty(key)) {         ar[key] = obj[key];     } } 

...except you'll have detect obj[key] object , recurse, i'll leave exercise reader.


note in javascript, arrays aren't arrays. depending on use-case, may not need conversion object array @ all.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -