i have create web service :
demo.asmx
<%@ WebService Language="C#" CodeBehind="~/App_Code/demo.cs" Class="demo" %>
demo.cs
public class demo : System.Web.Services.WebService
{
public demo()
{
}
[WebMethod]
[ScriptMethod(UseHttpGet = true, XmlSerializeString = false, ResponseFormat = ResponseFormat.Json)]
public string saveUserData()
{
Employee[] emps = new Employee[] {
new Employee()
{
Id=1,
Name="xyz"
},
new Employee()
{
Id=2,
Name="abc"
}
};
return new JavaScriptSerializer().Serialize(emps);
}
}
Now when i run this then it gives me below data:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<string>[{"Id":1,"Name":"xyz"},{"Id":2,"Name":"abc"}]</string>
so i have check the console and it gives me the
Cache-Control → private, max-age=0
Content-Encoding → gzip
Content-Length → 232
Content-Type → text/xml; charset=utf-8
Date → Sat, 05 Mar 2016 06:33:53 GMT
Server → Microsoft-IIS/8.0
Vary → Accept-Encoding
X-AspNet-Version → 4.0.30319
X-Powered-By → ASP.NET
X-SourceFiles → =?UTF-8?B?RDpcRGVtb193ZWJz
Its gives content type is text/xml
even i have define the Json response format.
How can i get only json response like below ?
[{"Id":1,"Name":"xyz"},{"Id":2,"Name":"abc"}]