JSON对象转字符串


 1        /**
 2         * json对象转字符串形式
 3         */
 4         function json2str(o) {
 5             var arr = [];
 6             var fmt = function(s) {
 7                 if (typeof s == 'object' && s != nullreturn json2str(s);
 8                 return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
 9             }
10             for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
11             return '{' + arr.join(','+ '}';
12         }
posted @ 2009-05-07 23:24  Pynix  阅读(3374)  评论(0编辑  收藏  举报