格式设置,自己想写什么样都可以。
public class LJsonResult : JsonResult
{
public int StatusCode { get; }
public LJsonResult(dynamic result, int statusCode=200, JsonRequestBehavior jsonRequestBehavior= JsonRequestBehavior.AllowGet)
{
StatusCode = statusCode;
Data = result;
JsonRequestBehavior = jsonRequestBehavior;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)throw new ArgumentNullException("Context is null.");
if ((JsonRequestBehavior == JsonRequestBehavior.DenyGet) && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("JsonRequest_GetNotAllowed");
var response = context.HttpContext.Response;
response.ContentType = !string.IsNullOrEmpty(this.ContentType) ? this.ContentType : "application/json";
if (ContentEncoding != null)response.ContentEncoding = this.ContentEncoding;
if (Data != null)response.Write(JsonConvert.SerializeObject(Data, new JsonSerializerSettings { DateFormatString = "yyyy/MM/dd HH:mm:ss" }));
response.StatusCode = StatusCode;
}
}
用js转一下就要以了
我现在写一个万能的方法,转换的。
配置一下就行了..这个东西是可以配置的.默认序列化方式.