Link to home
Start Free TrialLog in
Avatar of joshbula
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.  
<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>

Open in new window


I tried using JSON.NET...
    public string Get(int id)
    {
        DataTable person = MemberFunctions.GetContactInfo(id);
        return JsonConvert.SerializeObject(person);   
    }

Open in new window


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>

Open in new window

How can I get WebAPI in a WebForms app to return valid JSON instead of XML, preferably using JSON.NET?
ASKER CERTIFIED SOLUTION
Avatar of joshbula
joshbula

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial