工作心得网

工作心得精彩分享
代码积累持续学习

json返回数据格式

/// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="resultCode"></param>
        /// <param name="resultMsg"></param>
        /// <param name="obj"></param>
        public ResultInfo(int resultCode, string resultMsg, T obj)
        {
            ResultCode = resultCode;
            ResultMsg = resultMsg;
            ResultObj = obj;
        }
        /// <summary>
        /// 返回码
        /// </summary>
        private int resultCode;
        public int ResultCode
        {
            get { return resultCode; }
            set
            {
                this.resultCode = value;
                if (Resource.Codes.ContainsKey(value))
                {
                    if (this.ResultMsg == null || this.ResultMsg == "")
                    {
                        this.ResultMsg = Resource.Codes[value].cn;
                    }
                }
            }
        }

 


返回统一调用:
正常返回:
return JsonHelper.ToJson(new ResultInfo<string>(0, "", “返回数据”)); 
错误返回:
return JsonHelper.ToJson(new ResultInfo<string>(-1, "错误码或者错误提示", “”)); 

我们的缺点麻烦您能提出,谢谢支持!

关于站长