How do I get ASP.NET Web API to return JSON instead of XML using Chrome

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Using the newer ASP.NET Web API , in Chrome I am seeing XML - how can I change it to request JSON so I can view it in the browser? I do believe it is just part of the request headers, am I correct in that?

Answers

I just add the following in App_Start / WebApiConfig.cs class in my MVC Web API project.

config.Formatters.JsonFormatter.SupportedMediaTypes
    .Add(new MediaTypeHeaderValue("text/html") );

That makes sure you get json on most queries, but you can get xml when you send text/xml.

http://stackoverflow.com/a/20556625/287145 http://stackoverflow.com/a/20556625/287145

NameSpace is using System.Net.Http.Headers;

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using-chrome

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils