ASP.NET Web API to return JSON instead of XML

Before going to learn  how do I get asp.net web API to return json instead of xml lets go we know what is ASP.NET Web API and why use (Please Click this Link ……………).

Let’s Start:

Open visual studio 2013 Click New Project .

shamim'1 Blog

New window will appear and in this window give a name of your project or solution.

shamimblogApi2

Click Ok and another window will appear with project template, choose Web API .

3

Click OK and Visual studio will Create and load new asp.net Application Template.

4

And run project

5

Write url in browser Like- localhost/api/values and enter

6

We see that xml format values value1 and value2 . ASP.NET Wep API return by default  xml format value

But we want to json format value.

Ok lest’s go

Click App_Start  folder. There are 4 Class like BundleConfig, FilterConfig, RouteConfig, WebApiConfig in this App_start folder.And Click WebApiConfig.

7

Write the code within WebApiConfig Class

Run project and Write url in browser Like- localhost/api/values and enter

9

Hope this will be helpful.

3 thoughts on “ASP.NET Web API to return JSON instead of XML

Leave a Reply

Your email address will not be published. Required fields are marked *