WebHost/Extention/ExJsonResult.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebUI.Extention
{
public class ExJsonResult : JsonResult
{
public ExJsonResult(object obj)
{
base.Data = obj;
}
public override void ExecuteResult(ControllerContext context)
{
string json = JsonConvert.SerializeObject(Data, new ExJsonConverter());
context.HttpContext.Response.ContentType = "application/json";
context.HttpContext.Response.Write(json);
}
public class ExJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(long) || objectType.IsEnum || (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(Nullable<>) && objectType.GetGenericArguments()[0] == typeof(DateTime)) || objectType == typeof(DateTime) || objectType == typeof(String);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value != null)
{
string str = string.Empty;
if (value is DateTime)
{
DateTime dt;
DateTime.TryParse(value.ToString(), out dt);
str = dt.ToString("yyyy-MM-dd HH:mm:ss");
}
if (value is long)
{
str = value.ToString();
}
if (value is string)
{
str = Utility.NoHTML(value.ToString());
}
writer.WriteValue(str);
}
后面还有 9 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
