<small id='gc1cz'></small><noframes id='gc1cz'>

  1. <tfoot id='gc1cz'></tfoot>
    <i id='gc1cz'><tr id='gc1cz'><dt id='gc1cz'><q id='gc1cz'><span id='gc1cz'><b id='gc1cz'><form id='gc1cz'><ins id='gc1cz'></ins><ul id='gc1cz'></ul><sub id='gc1cz'></sub></form><legend id='gc1cz'></legend><bdo id='gc1cz'><pre id='gc1cz'><center id='gc1cz'></center></pre></bdo></b><th id='gc1cz'></th></span></q></dt></tr></i><div id='gc1cz'><tfoot id='gc1cz'></tfoot><dl id='gc1cz'><fieldset id='gc1cz'></fieldset></dl></div>

    <legend id='gc1cz'><style id='gc1cz'><dir id='gc1cz'><q id='gc1cz'></q></dir></style></legend>
      • <bdo id='gc1cz'></bdo><ul id='gc1cz'></ul>

      Web API 序列化从小写字母开始的属性

      时间:2023-08-23
          <tbody id='zZkVh'></tbody>

        <small id='zZkVh'></small><noframes id='zZkVh'>

        <legend id='zZkVh'><style id='zZkVh'><dir id='zZkVh'><q id='zZkVh'></q></dir></style></legend>
        <i id='zZkVh'><tr id='zZkVh'><dt id='zZkVh'><q id='zZkVh'><span id='zZkVh'><b id='zZkVh'><form id='zZkVh'><ins id='zZkVh'></ins><ul id='zZkVh'></ul><sub id='zZkVh'></sub></form><legend id='zZkVh'></legend><bdo id='zZkVh'><pre id='zZkVh'><center id='zZkVh'></center></pre></bdo></b><th id='zZkVh'></th></span></q></dt></tr></i><div id='zZkVh'><tfoot id='zZkVh'></tfoot><dl id='zZkVh'><fieldset id='zZkVh'></fieldset></dl></div>

          1. <tfoot id='zZkVh'></tfoot>
              • <bdo id='zZkVh'></bdo><ul id='zZkVh'></ul>
                本文介绍了Web API 序列化从小写字母开始的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                如何配置我的 Web API 的序列化以使用 camelCase(从小写字母开始)属性名称,而不是像在 C# 中那样使用 PascalCase.

                How can I configure serialization of my Web API to use camelCase (starting from lowercase letter) property names instead of PascalCase like it is in C#.

                我可以为整个项目全局做吗?

                Can I do it globally for the whole project?

                推荐答案

                如果你想改变 Newtonsoft.Json aka JSON.NET 中的序列化行为,你需要创建你的设置:

                If you want to change serialization behavior in Newtonsoft.Json aka JSON.NET, you need to create your settings:

                var jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings 
                { 
                    ContractResolver = new CamelCasePropertyNamesContractResolver(),
                    NullValueHandling = NullValueHandling.Ignore // ignore null values
                });
                

                您也可以将这些设置传递给 JsonConvert.SerializeObject:

                You can also pass these settings into JsonConvert.SerializeObject:

                JsonConvert.SerializeObject(objectToSerialize, serializerSettings);
                

                用于 ASP.NET MVC 和 Web API.在 Global.asax 中:

                protected void Application_Start()
                {
                   GlobalConfiguration.Configuration
                      .Formatters
                      .JsonFormatter
                      .SerializerSettings
                      .ContractResolver = new CamelCasePropertyNamesContractResolver();
                }
                

                排除空值:

                GlobalConfiguration.Configuration
                    .Formatters
                    .JsonFormatter
                    .SerializerSettings
                    .NullValueHandling = NullValueHandling.Ignore;
                

                表示结果 JSON 中不应包含空值.

                Indicates that null values should not be included in resulting JSON.

                ASP.NET Core 默认以驼峰格式序列化值.

                ASP.NET Core by default serializes values in camelCase format.

                这篇关于Web API 序列化从小写字母开始的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何提高 .Net 中的 JSON 反序列化速度?(JSON.net 还是 下一篇:JSON.NET JObject - 我如何从这个嵌套的 JSON 结构中获

                相关文章

                最新文章

                <legend id='3AKSG'><style id='3AKSG'><dir id='3AKSG'><q id='3AKSG'></q></dir></style></legend>
                <i id='3AKSG'><tr id='3AKSG'><dt id='3AKSG'><q id='3AKSG'><span id='3AKSG'><b id='3AKSG'><form id='3AKSG'><ins id='3AKSG'></ins><ul id='3AKSG'></ul><sub id='3AKSG'></sub></form><legend id='3AKSG'></legend><bdo id='3AKSG'><pre id='3AKSG'><center id='3AKSG'></center></pre></bdo></b><th id='3AKSG'></th></span></q></dt></tr></i><div id='3AKSG'><tfoot id='3AKSG'></tfoot><dl id='3AKSG'><fieldset id='3AKSG'></fieldset></dl></div>

                  1. <small id='3AKSG'></small><noframes id='3AKSG'>

                    • <bdo id='3AKSG'></bdo><ul id='3AKSG'></ul>
                  2. <tfoot id='3AKSG'></tfoot>