javasc json转String

来源:互联网 发布:client mac and addr 编辑:程序博客网 时间:2024/06/05 22:32

困然了很久,网上找了一段代码,复制过来用

json2str: function(o) { var arr = []; var fmt = function(s) { if (typeof s == 'object' && s != null) return _this.json2str(s);         return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s; } for (var i in o) arr.push("'" + i + "':" + fmt(o[i])); return '{' + arr.join(',') + '}'; }
后来才知道不用这么麻烦:

var obj = JSON.stringify(data);


转回对象:

data=JSON.parse(obj);

干干净净

0 0
原创粉丝点击