【发布时间】:2010-09-21 19:53:07
【问题描述】:
我有一个使用 jquery ajax 调用的 c# Web 服务。它工作正常,除非在 web 方法中引发自定义异常。出于某种原因,XmlHttpResponse 对象 responseText 仅具有基 Exception 类的属性。所以我最终得到了一个具有以下属性的 json 对象:“ExceptionType”、“Message”和“StackTrace”
我的自定义异常有一个名为“FieldErrors”的属性,它没有显示在返回中。这是该类的代码:
[Serializable]
[XmlRootAttribute(Namespace = "http://www.mydomain.com/", IsNullable = false)]
public class ValidationException : Exception
{
public List<string> FieldErrors { get; set; }
public ValidationException(string message = null, Exception innerException = null) : base(message: message, innerException: innerException)
{
this.FieldErrors = new List<string>();
}
}
我的目标是让“FieldErrors”属性显示在 json 响应中。
【问题讨论】:
-
我从来没有使用过 JSON 的东西,但是如果你使用
SoapException会有帮助吗? -
嗨。看来 SoapException 没有帮助:(。我仍然没有看到自定义属性
标签: c# jquery json serialization asmx