Web API 默认是返回JSON和XML的,在WebApiConfig的Register方法里可以去掉XML formatter
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//remove xml, default json
config.Formatters.Remove(config.Formatters.XmlFormatter);
}
}