zoukankan      html  css  js  c++  java
  • 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"));
    

      

  • 相关阅读:
    java学习笔记05--字符串 .
    java学习笔记04--数组
    java学习笔记07--日期操作类
    java学习笔记14--动态代理
    java学习笔记09--反射机制
    java学习笔记06--正则表达式
    java学习笔记08--泛型
    java学习笔记10--枚举
    java学习笔记11--Annotation
    交叉熵代价函数
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/7325421.html
Copyright © 2011-2022 走看看