[C#] 纯文本查看 复制代码 public class JsonResultHelper<T>
{
/// <summary>
/// 消息代码(负值为错误,0 为正确,正值为特殊约定)
/// </summary>
[JsonProperty("msgCode")]
public int msgCode { get; set; }
/// <summary>
/// 消息(辅助文本)
/// </summary>
[JsonProperty("msg")]
public string msg { get; set; }
/// <summary>
/// 动态数据封装
/// </summary>
[JsonProperty("info")]
public T info { get; set; }
/// <summary>
/// 将Json数据写入HTTP响应流中并结束响应
/// </summary>
/// <param name="context">HTTP请求上下文</param>
public void Send(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write(JsonHelper.ObjToJson(this));
context.Response.End();
}
/// <summary>
/// 将Json数据写入页面HTTP相应流,并结束响应
/// </summary>
/// <param name="response"></param>
public void Send(HttpResponse response)
{
response.Clear();
response.ContentType = "text/plain";
response.Write(JsonHelper.ObjToJson(this));
response.End();
}
}
|