The
is actually a JSON format problem and we should format it when we return JSON, and we need to rewrite the system's Jsonresult class
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using SYSTEM.WEB.MVC;
Using System.Text.RegularExpressions;
Using System.Web;
Using System.Web.Script.Serialization; Namespace App.common {public class Tojsonresult:jsonresult {const string error = "The request has been blocked because sensitive information is disclosed to a third party Web site, which is used when a GET request. In order to be able to get requests, please set Jsonrequestbehavior allowget.
";
<summary>///formatted string///</summary> public string Formatestr {
Get
Set
override void Executeresult (ControllerContext context) {if (context = null)
{throw new ArgumentNullException ("context"); } if (Jsonrequestbehavior = = Jsonrequestbehavior.denyget && string.equals (context). HttpContext.Request.HttpMethod, "get", StringComparison.OrdinalIgnoreCase)) {throw new Invali DoperationException (Error); } httpresponsebase response = context.
Httpcontext.response; if (! String.IsNullOrEmpty (ContentType)) {response.
ContentType = ContentType; else {response.
ContentType = "Application/json"; } if (contentencoding!= null) {response.
ContentEncoding = contentencoding; } if (Data!= null) {JavaScriptSerializer serializer = new JavaScriptSerializer ()
; String jsonstring = serializer.
Serialize (Data);
String p = @ "\\/date\ ((\d+) \+\d+\) \\/";
String p = @ "\\/date\ (\d+\) \\/";
MatchEvaluator matchevaluator = new MatchEvaluator (convertjsondatetodatestring);
Regex reg = new regex (p); jsonstring = Reg. Replace (jsonstring, MatchevaLuator); Response.
Write (jsonstring); }///<summary>///converts JSON serialization time from/date (1294499956278+0800) to string///</summa Ry> private String convertjsondatetodatestring (Match m) {string result = string.
Empty;
String p = @ "\d";
var CArray = M.value.tochararray ();
StringBuilder sb = new StringBuilder ();
Regex reg = new regex (p); for (int i = 0; i < carray.length; i++) {if Reg. IsMatch (Carray[i]. ToString ())) {sb.
Append (Carray[i]); }//Reg.
Replace (M.value;
DateTime dt = new DateTime (1970, 1, 1); DT = dt. Addmilliseconds (Long. Parse (sb.)
ToString ())); DT = dt.
ToLocalTime (); result = dt.
ToString ("Yyyy-mm-dd HH:mm:ss"); return result;
}
}
}