Friday, February 7, 2014

Return JSON in web-service ASMX

Returning JSON in ASMX web service is quite simple using JavaScriptSerialization

Step1:
Simply tag your webmethod

[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]

Setp2:
and now using JavaScriptSerializer, serialize your object and simply return it.

new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(company);

for more information around click JavaScriptSerializer

No comments: