开发者

Webmethod in aspx page receives and returns JSON string, how?

I have been experimenting with jquery ajax and discovered the following things:

If I have a webmethod, in an aspx page not a service, that looks like this:

   [System.Web.Services.WebMethod]  
    public static List<Person> SearchSrf(SearchCriteria search)
    {
        List<Person> people = new List<Person>();
      开发者_高级运维   //add persons to the list etc.
        return people ;
    }

And javascript that looks like this:

     var objSearch = new Object();
     object [FirstName] = 'Joe'
     //etc
    var DTO = { 'search': objSearch };
     then in my ajax call I set data: JSON.stringify(DTO)
  1. If I send data to the method through jquery ajax passing the object created in javascript with properties that match my search object and with the name of search .net successfully deserializes that JSON string to a search object.
  2. When I return list it also serializes it as a JSON string.

My question is how/why is this happening? I know that in my ajax call I set the dataType to json, but how does .net understand this without any decorating of the method or other configuration to let it know the format.

How/why is the return list serialized to a JSON string without any hint to do so?


I'm just guessing here, but I'd assume it's pulling the request type from the http headers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜