• WebApi——json返回多了 k_BackingField


    产生原因:

    model类添加了    [System.Serializable]

    解决方案:

    xxxxx.WebApiApp_StartWebApiConfig.cs的Register函数中添加如下代码

                config.Formatters.XmlFormatter.UseXmlSerializer = true;
                config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("$Format", "xml", "application/xml"));
                config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("OutputFormat", "xml", "application/xml"));
                config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
    
                var serializerSettings =
                  GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
                var contractResolver =
                  (DefaultContractResolver)serializerSettings.ContractResolver;
                contractResolver.IgnoreSerializableAttribute = true;
                //config.Formatters.Insert(0, new JsonpFormatter());
                config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
                config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("$Format", "json", "application/json"));
                config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("OutputFormat", "json", "application/json"));
    

      

  • 相关阅读:
    (7)排序之归并排序
    (5)排序之简单选择排序
    (4)排序之希尔排序
    (3)排序之直接插入排序
    (2)排序之快速排序
    (1)排序之冒泡排序
    Python学习
    centos下docker网络桥接
    docker下搭建gitlab
    centos版本7以上网卡名修改
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/7325421.html
Copyright © 2020-2023  润新知