日期:2014-05-16 浏览次数:20411 次
var str = '{ "name": "cxh", "sex": "man" }';
var str2 = { "name": "cxh", "sex": "man" };
/** * 由JS对象转换成JSON字符串 */ array.toJSONString() boolean.toJSONString() date.toJSONString() number.toJSONString() object.toJSONString() string.toJSONString() /** * 由JS字符串转换成JSON对象 */ s.parseJSON(filter)
return '[' + a.join(',') + ']';
return String(this);
return '"' + this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z"';
return isFinite(this) ? String(this) : 'null';
<script type="text/javascript"> var obj = {}; obj.name = 'zhangsan'; alert(obj.toJSONString()); </script>
var a = []; a.push(k.toJSONString() + ':' + v.toJSONString()); return '{' + a.join(',') + '}';
if (/["\\\x00-\x1f]/.test(this)) { return '"' + this.replace(/[\x00-\x1f\\"]/g, function (a) { var c = m[a]; if (c) { return c; } c = a.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }) + '"'; } return '"' + this + '"';
s.parseJSON = function (filter) { ...... return filter(k, v); }
new Date().toJSONString().parseJSON() 或 var array = [1, 2, 3, 4]; alert(array.toJSONString().parseJSON());
Example: // Parse the text. If a key contains the string 'date' then convert the value to a date. myData = text.parseJSON(function (key, value) { return key.indexOf('date') >= 0 ? new Date(value) : value; });