function json2str(o) { var arr = []; var fmt = function(s) { if (typeof s == ‘object‘ && s != null) return json2str(s); return /^(string|number)$/.test(typeof s) ? ‘"‘ + s + ‘"‘ : s; } for (var i in o) arr.push("‘" + i + "‘:" + fmt(o[i])); return ‘{‘ + arr.join(‘,‘) + ‘}‘; } //json2str({a:1,sd:3}) //"{‘a‘:"1",‘sd‘:"3"}"
来自 : http://www.jb51.net/article/32825.htm
时间: 2024-10-12 12:59:49