方便统一ashx返回类型~ weiapi也行~
/// <summary> /// 返回数据 /// </summary> public class ResultData { /// <summary> /// 操作状态 /// </summary> public ResultDataStateEnum code { get; set; } /// <summary> /// 返回的数据集 /// </summary> public dynamic data { get; set; } /// <summary> /// 信息 /// </summary> public string msg { get; set; } /// <summary> /// 返回成功 /// </summary> /// <param name="data"></param> /// <param name="message"></param> /// <returns></returns> public static ResultData Access() { var r = new ResultData() { code = ResultDataStateEnum.正常 }; return r; } /// <summary> /// 返回成功 /// </summary> /// <param name="data"></param> /// <param name="message"></param> /// <returns></returns> public static ResultData Access(string message) { var r = new ResultData() { code = ResultDataStateEnum.正常, msg = message }; return r; } /// <summary> /// 返回成功 /// </summary> /// <param name="data"></param> /// <param name="message"></param> /// <returns></returns> public static ResultData Access(dynamic data) { var r = new ResultData() { code = ResultDataStateEnum.正常, data = data }; return r; } /// <summary> /// 返回失败 /// </summary> /// <param name="message"></param> /// <returns></returns> public static ResultData Fail(string message = "") { var r = new ResultData() { code = ResultDataStateEnum.错误, msg = message }; return r; } /// <summary> /// 返回失败 /// </summary> /// <param name="message"></param> /// <returns></returns> public static ResultData Fail2(string message = "") { var r = new ResultData() { code = ResultDataStateEnum.登录失败, msg = message }; return r; } /// <summary> /// 返回失败 /// </summary> /// <param name="data"></param> /// <returns></returns> public static ResultData Fail(object data) { var r = new ResultData() { code = ResultDataStateEnum.错误, data = data }; return r; } /// <summary> /// 将返回数据转为json字符串 /// </summary> /// <param name="r"></param> /// <returns></returns> public static string toJson(ResultData r) { var model_JsonSerializerSettings = new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, // DateFormatString = "yyyy-MM-dd HH:mm:ss" //输出时间格式 //其他以后补充 }; return JsonConvert.SerializeObject(r, Formatting.Indented, model_JsonSerializerSettings); } public enum ResultDataStateEnum { 登录失败 = -1, 正常 = 0, 错误 = 1, 提示 = 2 } }