C#构造Json返回值帮助类库源码下载
JsonModel Json返回值帮助类用法: JsonMsgRet<string> ret=New JsonMsgRet<string>();//返回值类型一 JsonMsgRet<info> ret=New JsonMsgRet<info>();//返回值类型二 JsonMsgRet<List<info>> ret=New JsonMsgRet<List<info>>();//返回值类型三 使用说明,例如: info myinfo=new info(); JsonMsgRet<info> ret = new JsonMsgRet<info>(); ret.Content = "请求成功www.yunjson.com"; ret.RetrunValue = myinfo; //JsonHelper帮助类 json转换类下载地址 //下载地址:http://www.yunjson.com/articleinfo/20/ //JsonHelper使用教程:http://www.yunjson.com/articleinfo/2/ context.Response.Write(JsonHelper.json(ret));
组织json返回值类 源码
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace JsonModel { /// <summary> /// 组织json返回值类 /// 来源:www.jsons.cn /// </summary> public class JsonMsgRet<T> { private MsgStatus _Status = MsgStatus.Failed; /// <summary> /// 返回状态 /// </summary> public MsgStatus Status { set { _Status = value; } get { return _Status; } } private string _Content = string.Empty; /// <summary> /// 返回内容(string类型) /// </summary> public string Content { set { _Content = value; } get { return _Content; } } private T _RetrunValue =default(T); /// <summary> /// 返回值 (可自定义类型:string、实体对象、List都可以) /// </summary> public T RetrunValue { set { _RetrunValue = value; } get { return _RetrunValue; } } } /// <summary> /// 构造返回值状态:用于标志请求是否成功(返回值可自行定义) /// </summary> public enum MsgStatus { /// <summary> /// 成功 /// </summary> OK = 0, /// <summary> /// 失败 /// </summary> Failed = 1, } }
原文链接:C#.Net构造Json返回值帮助类 面向对象泛型集合类