joshbula
asked on
Web API in WebForms app returning XML instead of JSON
I added Web API to my existing Web Forms (NOT MVC) ASP.NET application using these instructions:
http://blogs.msdn.com/b/henrikn/archive/2012/02/23/using-asp-net-web-api-with-asp-net-web-forms.aspx
http://dotnet.dzone.com/articles/web-api-aspnet-web-forms
But, they return XML.
I tried using JSON.NET...
and it generates the JSON I need but it is still wrapped in XML tags:
http://blogs.msdn.com/b/henrikn/archive/2012/02/23/using-asp-net-web-api-with-asp-net-web-forms.aspx
http://dotnet.dzone.com/articles/web-api-aspnet-web-forms
But, they return XML.
<ArrayOfstring xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>value1</string>
<string>value2</string>
</ArrayOfstring>
I tried using JSON.NET...
public string Get(int id)
{
DataTable person = MemberFunctions.GetContactInfo(id);
return JsonConvert.SerializeObject(person);
}
and it generates the JSON I need but it is still wrapped in XML tags:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
[{"Prefix":"Dr","FirstName":"Josh", ....etc....... }]
</string>
How can I get WebAPI in a WebForms app to return valid JSON instead of XML, preferably using JSON.NET?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.