zoukankan      html  css  js  c++  java
  • WebApi返回Json

    参考地址:http://www.cnblogs.com/acles/archive/2013/06/21/3147667.html

     1  public static void Register(HttpConfiguration config)
     2         {
     3             config.Routes.MapHttpRoute(
     4                 name: "ApiV1",
     5                 routeTemplate: "datasvc/v1/{action}",
     6                 defaults: new { controller = "ApiV1" }
     7             );
     8             config.EnableSystemDiagnosticsTracing();
     9 
    10             var jsonFormatter = new JsonMediaTypeFormatter();
    11             config.Services.Replace(typeof(IContentNegotiator), new 
    12               JsonContentNegotiator(jsonFormatter));
    13         }

    ----------------------------------------------------------------------------------------

    public class JsonContentNegotiator : IContentNegotiator
        {
            private readonly JsonMediaTypeFormatter _jsonFormatter;
    
            public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
            {
                _jsonFormatter = formatter;
            }
    
            public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
            {
                var result = new ContentNegotiationResult(_jsonFormatter, new MediaTypeHeaderValue("application/json"));
                return result;
            }
        }
  • 相关阅读:
    centos7上安装JupyterHub
    我的测试第一篇博客
    TCP,SYN,FIN扫描
    nmap使用帮助翻译
    MySQL 常用函数
    MySQL 视图
    MySQL 索引
    JAVA 注解
    JAVA 反射
    spring boot MySQL极简封装
  • 原文地址:https://www.cnblogs.com/sunzhenyong/p/9928682.html
Copyright © 2011-2022 走看看