This article will share with you the code for converting arrays into json using javascript, which is very simple and practical, equivalent to JSON. stringify (array);. if you need it, you can refer to it. Js converts arrays to json
Function arrayToJson (o) {var r = []; if (typeof o = "string") return "\" "+ o. replace (/([\ '\ "\])/g," \ $1 "). replace (/(\ n)/g, "\ n "). replace (/(\ r)/g, "\ r "). replace (/(\ t)/g, "\ t") + "\" "; if (typeof o =" object ") {if (! O. sort) {for (var I in o) r. push (I + ":" + arrayToJson (o [I]); if (!! Document. all &&! /^ \ N? Function \ s * toString \ (\) \ s * \ {\ n? \ S * \ [native code \] \ n? \ S * \} \ n? \ S * $ /. test (o. toString) {r. push ("toString:" + o. toString. toString ();} r = "{" + r. join () + "}" ;}else {for (var I = 0; I <o. length; I ++) {r. push (arrayToJson (o [I]);} r = "[" + r. join () + "]";} return r;} return o. toString ();}
Equivalent to JSON. stringify (array );
The above is all the content of this article. I hope you will like it.