陈斌彬的技术博客

Stay foolish,stay hungry

ASP.NET Web API 返回 JSON 而不是 XML

MVC4 快速从 ASP.NET 的 Web API 移除 XML 格式化在 Global.asax 添加一行:

GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

像这样:

protected void Application_Start()
{
 AreaRegistration.RegisterAllAreas();
 RegisterGlobalFilters(GlobalFilters.Filters);
 RegisterRoutes(RouteTable.Routes);
 BundleTable.Bundles.RegisterTemplateBundles();
 GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
}