/// <summary> /// 设置结果 /// </summary> /// <param name="data">数据</param> /// <param name="msg">消息类型</param> /// <param name="error">错误码</param> /// <returns>返回设置后的字符串</returns> public string SetRet(object data = null, string msg = "", int error = 0) { if (Ret == null) { Ret = new ApiRetModel(error, msg); } else if (data != null) { Ret.Result = data; } string ret = ""; if (string.IsNullOrEmpty(ContentType)) { ret = Ret.ToJson(); } else { if (ContentType.Contains("json")) { ret = Ret.ToJson(); } else if (ContentType.Contains("xml")) { ret = Ret.ToXmlS(); } else { var err = Ret.Error; if (err != null) { ret += "error: " + err.Code + V; ret += "msg: " + err.Message + V; } ret += "data: " + Ret.Result; } } return(ret); }