This article is mainly to the JS object to the JSON array of simple implementation of the case is introduced, the need for friends can come to the reference, I hope to help you
The code is as follows: function Obj2str (obj) {switch (typeof (obj)) {case ' object ': var ret = []; if (obj instanceof Array) {for (var i = 0, len = obj.length i < len; i++) {Ret.push (Obj2str (obj[i))); Return ' [' + ret.join (', '] + '] '; else if (obj instanceof RegExp) {return obj.tostring (); } else{for (var a in obj) {Ret.push (A + ': ' + obj2str (Obj[a])); Return ' {' + ret.join (', ') + '} '; Case ' function ': return ' function () {} '; Case ' number ': return obj.tostring (); Case ' string ': Return ' "" + obj.replace (/(|)) /g, "$". Replace (/n|r|t/g, function (a) {return ("n" ==a)? N ":(" R "==a"? R ":(" T "==a"? T ":";}) + """; Case ' Boolean ': Return Obj.tostring (); Default:return obj.tostring (); } }