views:

127

answers:

1

If I have a web service (.asmx) and I want it to use Json.NET to serialize all the objects that I return from that web service, is there a way to do that?

In other words, I have a class like this:

    [JsonObject(MemberSerialization.OptOut)]
    public partial class Person
    {
        public string FirstName {get; set;}

        public string LastName {get; set;}

        [JsonIgnore]    
        public string Password {get; set;}    
    }

And in my web service, I have this:

    [WebMethod]
    public Person GetBlahPerson()
    {
        Person p = new Person();
        p.FirstName = "bob";
        p.LastName = "smith";
        p.Password = "don't tell";

        return p;
    }

If using jQuery I set the return type to json, it serializes my object to json.

Is it possible to make it use Json.net through a setting in web.config or something similar?