使C# WebApi返回Json

找到Global.asax文件,在Application_Start()方法中添加一句:

复制代码
protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 
    WebApiConfig.Register(GlobalConfiguration.Configuration); 
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
    RouteConfig.RegisterRoutes(RouteTable.Routes); 
    // 使api返回为json 
    GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); 
} 
复制代码
posted @ 2019-08-02 11:51  forever2015  阅读(730)  评论(0编辑  收藏  举报