如果我有一个 Web 服务 (.asmx) 并且我希望它使用 Json.NET 来序列化我从该 Web 服务返回的所有对象,有没有办法做到这一点?
换句话说,我有一个这样的课程:
[JsonObject(MemberSerialization.OptOut)]
public partial class Person
{
public string FirstName {get; set;}
public string LastName {get; set;}
[JsonIgnore]
public string Password {get; set;}
}
在我的网络服务中,我有这个:
[WebMethod]
public Person GetBlahPerson()
{
Person p = new Person();
p.FirstName = "bob";
p.LastName = "smith";
p.Password = "don't tell";
return p;
}
如果使用 jQuery 我将返回类型设置为 json,它会将我的对象序列化为 json。
是否可以通过 web.config 中的设置或类似的设置使其使用 Json.net?