方法一
WEB API默认支持返回XML和JSON 格式数据,其根据WEB请求中指定的类型自动识别,但在本项目中只需要用json格式,而且为了在chrome中测试方便(用chrome浏览器默认返回是xml数据),限制其无论什么情况都返回JSON格式。
在Application_Start中加上:
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
方法二
上法或者太暴力了,来个温和点的
在Application_Start中加上:
GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new
QueryStringMapping(“format”, “json”, “application/json”));