简体   繁体   中英

Javascript multi-dimensional array to and from JSON (jQuery?)

I have a Javascript problem where I need to be able to store data like follows:

MainArray(Array(JavaScript Object, JavaScript Object, etc etc..), Array(JavaScript Object, JavaScript Object, etc etc..), etc etc..)

The main array has 10 sub arrays, these sub arrays then contain any number of JavaScript Objects.

I need an efficient way of storing the data this way and need to know how to parse to JSON/decode back to a manageable structure in Javascript.

The reason for this structure is because the Java program I'm communicating with uses this structure.

I'm able to use jQuery if that makes any difference.

Your structure appears to look like this

var myVariable = [
   [
       { }, { }, { }
   ],
   [
       { }, { }, { }
   ]
]

This can be JSON stringified. It yields "[[{},{},{}],[{},{},{}]]"

Use JSON.stringify and JSON.parse , respectively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM