Motive:. NET default time serialization mode is \/date (digital time zone)/, serialized into JSON is difficult to handle at the front end, is there a good way to handle it?
Improved:
1JSON =New function(){2 This. decode =function(){3 varfilter, result, self, tmp;4 if($$ ("toString")) {5 Switch(arguments.length) {6 Case2:7Self = arguments[0];8Filter = Arguments[1];9 Break;Ten Case1: One if($[typeofArguments[0]] (arguments[0]) = = =Function) { ASelf = This; -Filter = Arguments[0]; - } the Else -Self = arguments[0]; - Break; - default: +Self = This; - Break; + }; A if(Rc.test (self)) { at Try{ -result = E ("(". Concat (Self, ")")); - if(Filter && result!==NULL&& (tmp = $[typeofResult] (Result) && (tmp = = = Array | | tmp = = =Object)) { - for(Selfinchresult) -Result[self] = V (self, result)?filter (self, result[self]): result[self]; - } in } - Catch(z) {} to } + Else { - Throw NewError ("Bad data"); the } * }; $ returnresult;Panax Notoginseng }; - This. Encode =function(){ the varSelf = arguments.length? Arguments[0]: This, + result, TMP; A if(Self = = =NULL) theresult = "NULL"; + Else if(Self!== undefined && (tmp = $[typeofSelf ] (self))) { - Switch(TMP) { $ CaseArray: $result = []; - for(vari = 0, j = 0, k = self.length; J < K; J + +) { - if(Self[j]!== undefined && (tmp =Json.encode (Self[j] )) theresult[i++] =tmp; - };Wuyiresult = "[". Concat (Result.join (","), "]"); the Break; - CaseBoolean: Wuresult =String (self); - Break;In the case of date:57 result = ' "\\/date ('. Concat (Self.valueof (), ') \\/" '); 58 break; - CaseFunction: - Break; A CaseNumber : +result = Isfinite (self)? String (self): "null"; the Break; - CaseString: $result = ' "'. Concat (Self.replace (RS, s). replace (ru, u), '" '); the Break; the default: the vari = 0, key; theresult = []; - for(KeyinchSelf ) { in if(Self[key]!== undefined && (tmp =Json.encode (Self[key] )) theresult[i++] = ' "'. Concat (Key.replace (RS, s). replace (ru, u), '": ', TMP); the }; Aboutresult = "{". Concat (Result.join (","), "}"); the Break; the } the }; + returnresult; - }; the This. toDate =function(){Bayi varSelf = arguments.length? Arguments[0]: This, the result; the if(Rd.test (self)) { -result =NewDate (); -Result.sethours (I (Self, 11, 2)); theResult.setminutes (I (Self, 14, 2)); theResult.setseconds (I (Self, 17, 2)); theResult.setmonth (I (Self, 5, 2)-1); theResult.setdate (I (Self, 8, 2)); -Result.setfullyear (I (Self, 0, 4)); the }//else if (rt.test (self)),//result = new Date (self *), 94 else if (Rr.test (self)) {9 5 result=new Date (Self.match (/\d+/) [0]-0]; + +} the returnresult;98 }; About this.defaultdatefilter=function (k,m) {///provides a common time string parsing method (using the original processing mechanism as much as possible, this process consumes performance and requires a filter when parsing time) 101 switch ($ [typeof M] (m)) {102 Case array:103 case object:104 for (Var p in m) {m[p]=v (p,m)? Arguments.callee (P,m[p]): m[p];106 }107 return m;108 case string:109 return json.todate (m); default:111 return m;112}113 } the varc = {"\b": "b", "\ T": "T", "\ n": "N", "\f": "F", "\ R": "R", "" ': ' "'," \ \ ":" \ \ ","/":"/"}, theD =function(n) {returnN<10? " 0 ". Concat (n): n}, theE =function(c,f,e) {e=eval;DeleteEvalif(typeofeval=== "undefined") eval=e;f=eval ("" +c); eval=e;returnF},117i =function(e,p,l) {return1*e.substr (p,l)},118p = ["", "000", "00", "0", "" "],119rc =NULL, -RD =/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}t[0-9]{2}:[0-9]{2}:[0-9]{2}$/,121rs =/(\x5c|\x2f|\x22|[ \x0c-\x0d]| [\x08-\x0a]) /G,122 rr=/^\/date\ (\d+\) \/$/,123RT =/^ ([0-9]+|[ 0-9]+[,\.] [0-9] {1,3}) $/,124RU =/([\x00-\x07]|\x0b|[ \X0E-\X1F])/G, thes =function(i,d) {return"\\". Concat (C[d])},126U =function(i,d) {127 varN=d.charcodeat (0). toString (16); - return"\\u". Concat (p[n.length],n)129 }, thev =function(K,V) {return$[typeofResult] (Result)!==function&& (V.hasownproperty?v.hasownproperty (k): v.constructor.prototype[k]!==v[k])},131$ = { the"Boolean":function(){returnBoolean},133"Function":function(){returnFunction},134"Number":function(){returnNumber },135"Object":function(o) {returnOinstanceofO.constructor?o.constructor:NULL},136"String":function(){returnString},137"Undefined":function(){return NULL}138 },139$$ =function(m) { $ function$ (c,t) {t=c[m];DeleteC[M];Try{e (c)}Catch(z) {c[m]=t;return1}};141 return$ (Array) &&$ (Object)142 };143 Try{rc=NewRegExp (' ^ (\\\\.| [^ "\\\\\\n\\r]) *?"| [,: {}\\[\\]0-9.\\-+eaeflnr-u \\n\\r\\t]) +?$ ')}144 Catch(z) {rc=/^ (true|false|null|\[.*\]|\{.*\}| "). * "|\d+|\d+\.\d+) $/}145};
At this point, it's easy to fix the problem with JSON time processing. But here is a little bit imperfect place to ask. NET end of time using UTC time, generally this is not a major flaw, acceptable. My reason is that UTC time should be used on the server in the multi-temporal area.
Let Json.js fully adapt to. NET