X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..92c2b89db26be16707f4a805d3303ab2531006e1:/src/util/core/JSON.js diff --git a/src/util/core/JSON.js b/src/util/core/JSON.js index b4103d0b..6b1dd334 100644 --- a/src/util/core/JSON.js +++ b/src/util/core/JSON.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.0 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.1.1 + * Copyright(c) 2006-2010 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ @@ -31,35 +31,39 @@ Ext.util.JSON = new (function(){ return eval("(" + json + ')'); }, doEncode = function(o){ - if(typeof o == "undefined" || o === null){ + if(!Ext.isDefined(o) || o === null){ return "null"; }else if(Ext.isArray(o)){ return encodeArray(o); - }else if(Object.prototype.toString.apply(o) === '[object Date]'){ + }else if(Ext.isDate(o)){ return Ext.util.JSON.encodeDate(o); - }else if(typeof o == "string"){ + }else if(Ext.isString(o)){ return encodeString(o); }else if(typeof o == "number"){ + //don't use isNumber here, since finite checks happen inside isNumber return isFinite(o) ? String(o) : "null"; - }else if(typeof o == "boolean"){ + }else if(Ext.isBoolean(o)){ return String(o); }else { var a = ["{"], b, i, v; for (i in o) { - if(!useHasOwn || o.hasOwnProperty(i)) { - v = o[i]; - switch (typeof v) { - case "undefined": - case "function": - case "unknown": - break; - default: - if(b){ - a.push(','); + // don't encode DOM objects + if(!o.getElementsByTagName){ + if(!useHasOwn || o.hasOwnProperty(i)) { + v = o[i]; + switch (typeof v) { + case "undefined": + case "function": + case "unknown": + break; + default: + if(b){ + a.push(','); + } + a.push(doEncode(i), ":", + v === null ? "null" : doEncode(v)); + b = true; } - a.push(doEncode(i), ":", - v === null ? "null" : doEncode(v)); - b = true; } } } @@ -112,6 +116,18 @@ Ext.util.JSON = new (function(){ return a.join(""); }; + /** + *
Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal expression. + * The returned value includes enclosing double quotation marks.
+ *The default return format is "yyyy-mm-ddThh:mm:ss".
+ *To override this:
+Ext.util.JSON.encodeDate = function(d) {
+ return d.format('"Y-m-d"');
+};
+
+ * @param {Date} d The Date to encode
+ * @return {String} The string literal to use in a JSON string.
+ */
this.encodeDate = function(o){
return '"' + o.getFullYear() + "-" +
pad(o.getMonth() + 1) + "-" +