/// <summary>转换为字符串</summary> /// <param name="nobrace">对象不包含最外面的大括号</param> /// <returns></returns> public string ToString(bool nobrace) { StringBuilder outString = new StringBuilder(); if (!nobrace) { outString.Append("{"); } outString.Append("\"message\":{"); if (AjaxConfigurationView.Instance.NamingRule == "underline") { outString.AppendFormat("\"return_code\":\"{0}\",", StringHelper.ToSafeJson(this.ReturnCode)); } else { outString.AppendFormat("\"returnCode\":\"{0}\",", StringHelper.ToSafeJson(this.ReturnCode)); } outString.AppendFormat("\"value\":\"{0}\"", StringHelper.ToSafeJson(this.Value)); outString.Append("},"); // 是否成功执行 outString.Append("\"success\":1,\"msg\":\"success\""); if (!nobrace) { outString.Append("}"); } IMessageObjectFormatter formatter = (IMessageObjectFormatter)Activator.CreateInstance(Type.GetType(KernelConfigurationView.Instance.MessageObjectFormatter)); return(!nobrace?formatter.Format(outString.ToString(), nobrace) : formatter.Format(string.Concat("{", outString.ToString(), "}"), nobrace)); }
/// <summary>转换为字符串</summary> /// <param name="nobrace">对象不包含最外面的大括号</param> /// <returns></returns> public string ToString(bool nobrace) { StringBuilder outString = new StringBuilder(); if (!nobrace) { outString.Append("{"); } // messagejsonfoaater outString.Append("\"message\":{"); if (AjaxConfigurationView.Instance.NamingRule == "underline") { outString.AppendFormat("\"return_code\":\"{0}\",", StringHelper.ToSafeJson(this.m_ReturnCode)); } else { outString.AppendFormat("\"returnCode\":\"{0}\",", this.m_ReturnCode); } outString.AppendFormat("\"value\":\"{0}\"", StringHelper.ToSafeJson(this.InnerException == null ? this.Message : this.InnerException.Message)); outString.Append("},"); // 是否成功执行 outString.Append("\"success\":" + this.success + ","); if (this.success == 0) { // 如果是执行失败输出异常信息 outString.AppendFormat("\"msg\":\"{0}\"", StringHelper.ToSafeJson(this.InnerException == null ? this.Message : this.InnerException.ToString())); } else { // 如果是执行成功输出 success outString.AppendFormat("\"msg\":\"success\""); } if (!nobrace) { outString.Append("}"); } IMessageObjectFormatter formatter = (IMessageObjectFormatter)KernelContext.CreateObject(KernelConfigurationView.Instance.MessageObjectFormatter); return(!nobrace?formatter.Format(outString.ToString(), nobrace) : formatter.Format(string.Concat("{", outString.ToString(), "}"), nobrace)); }