Can anyone explain me how ASP.NET handles the convertion from a class object to the JSON object in WebMethods?
For example, you have following WebMethod which returns a Person object:
[WebMethod]
public static Person GetPerson()
{
Person p = new Person()
{
Id = 1,
Name = "Test"
};
return p;
}
In my jQuery where i call the WebMethod I get a response which contains out of a json object.
How did ASP.NET do this automatcally? Does it uses the JavaScriptSerializer class?
Also you see a lot of examples of using JSON converters to convert your class object to a json object. Why is this? Is it because of the JavaScriptSerializer class it uses and its bad performance or... ?
WebMethodisn't really supported anymore. If you need a JSON or XML based API, it's best to look to ASP.NET Web API, which uses Newtonsoft's Json.NET to handle JSON serialization.