How to convert a JSON multi-dimensional array to a JS multi-dimensional array

Source: Internet
Author: User
How to convert a JSON multi-dimensional array to a JS multi-dimensional array PHPcode & lt ;? Php $ arr1 = array (& quot; a & quot;, & quot; B & quot;, & quot; c & quot ;); $ arr2 = array (how to convert a JSON multi-dimensional array to a JS multi-dimensional array
PHP code
  
  


JScript code
  $. GetJSON ("../php/json. php? Parm = arr2 ", function (json) {// How to write in the middle });


If the final JS is
JScript code
  var arr1=["a","b","c"];        var arr2=[                ["a1","a2","a3"],                ["b1","b2","b3"],                ["c1","c2","c3"]        ];        var arr3=[                 [                    ["a11","a12","a13"],                    ["a21","a22","a23"],                    ["a31","a32","a33"]                 ],                 [                    ["b11","b12","b13"],                    ["b21","b22","b23"],                    ["b31","b32","b33"]                 ],                 [                    ["c11","c12","c13"],                    ["c21","c22","c23"],                    ["c31","c32","c33"]                 ]        ];


------ Solution --------------------
I am not so familiar with js, so I want to know that all of them are passed to js. what should I do if I want to restore them to an array?
------ Solution --------------------
The getJSON method of jquery has converted the received data into a json object array.
That is to say, json in function (json) is a json object array.
You can use json. name directly.
In general, it is over when used up.

According to your description, it seems that you want to construct a global variable from it.
You can use for (k in json) to traverse each member and use the eval function to import it to the global variable.
Of course, you have to construct the variable name by yourself, because your php code is not passed out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.