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

      <bdo id='EkDmF'></bdo><ul id='EkDmF'></ul>
    <tfoot id='EkDmF'></tfoot>
      1. <legend id='EkDmF'><style id='EkDmF'><dir id='EkDmF'><q id='EkDmF'></q></dir></style></legend>

        <i id='EkDmF'><tr id='EkDmF'><dt id='EkDmF'><q id='EkDmF'><span id='EkDmF'><b id='EkDmF'><form id='EkDmF'><ins id='EkDmF'></ins><ul id='EkDmF'></ul><sub id='EkDmF'></sub></form><legend id='EkDmF'></legend><bdo id='EkDmF'><pre id='EkDmF'><center id='EkDmF'></center></pre></bdo></b><th id='EkDmF'></th></span></q></dt></tr></i><div id='EkDmF'><tfoot id='EkDmF'></tfoot><dl id='EkDmF'><fieldset id='EkDmF'></fieldset></dl></div>
      2. 对象&amp;使用 JSON.Net 进行驼峰式转换

        时间:2023-08-23
        <tfoot id='loeAw'></tfoot><legend id='loeAw'><style id='loeAw'><dir id='loeAw'><q id='loeAw'></q></dir></style></legend>
        <i id='loeAw'><tr id='loeAw'><dt id='loeAw'><q id='loeAw'><span id='loeAw'><b id='loeAw'><form id='loeAw'><ins id='loeAw'></ins><ul id='loeAw'></ul><sub id='loeAw'></sub></form><legend id='loeAw'></legend><bdo id='loeAw'><pre id='loeAw'><center id='loeAw'></center></pre></bdo></b><th id='loeAw'></th></span></q></dt></tr></i><div id='loeAw'><tfoot id='loeAw'></tfoot><dl id='loeAw'><fieldset id='loeAw'></fieldset></dl></div>

              <bdo id='loeAw'></bdo><ul id='loeAw'></ul>

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

                    <tbody id='loeAw'></tbody>
                  本文介绍了对象&amp;使用 JSON.Net 进行驼峰式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何将通用 JObject 转换为 camelCase 纯 json 字符串?我试过 JsonSerializerSettings 但不起作用(Newtonsoft.Json 4.5.11)

                  How can I convert a generic JObject to camelCase plain json string? I've tried with JsonSerializerSettings but doesn't work (Newtonsoft.Json 4.5.11)

                  [Test]
                  public void should_convert_to_camel_case()
                  {
                      var serializer = JsonSerializer.Create(new JsonSerializerSettings()
                      {
                          ContractResolver = new CamelCasePropertyNamesContractResolver()
                      });
                  
                      var jo = new JObject();
                      jo["CamelCase"] = 1;
                  
                      var stringWriter = new StringWriter();
                      var writer = new JsonTextWriter(stringWriter);
                      serializer.Serialize(writer,jo);
                  
                      var serialized = stringWriter.ToString();
                  
                      Assert.AreEqual("{"camelCase":1}", serialized);
                  }
                  

                  更新根据 http://json.codeplex.com/workitem/23853 无法完成(tnx 到 @nick_w 获取链接)

                  UPDATE According to http://json.codeplex.com/workitem/23853 that cannot be done (tnx to @nick_w for the link)

                  推荐答案

                  这道题从一个JObject开始,想对一个驼峰式的JSON对象起作用.如果您实际上是从一个对象开始并想要获得一个已经被驼峰​​化的 JObject,那么您可以这样做:

                  This question starts from a JObject and wants to work to a camel-cased JSON object. If you are actually starting from an object and want to get to a JObject that is already camelcased, then you can do this:

                  var serializer = new JsonSerializer()
                  {
                      ContractResolver = new CamelCasePropertyNamesContractResolver()
                  };
                  var jo = JObject.FromObject(someDataContract, serializer);
                  

                  生成的 'jo' 将被驼峰化.

                  The resulting 'jo' will be camelcased.

                  这篇关于对象&amp;使用 JSON.Net 进行驼峰式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:收到错误“无法从 Newtonsoft.Json.Linq.JProperty 添加或 下一篇:Json.Net PopulateObject 追加列表而不是设置值

                  相关文章

                  最新文章

                      <bdo id='qzwOq'></bdo><ul id='qzwOq'></ul>

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

                  1. <legend id='qzwOq'><style id='qzwOq'><dir id='qzwOq'><q id='qzwOq'></q></dir></style></legend>
                  2. <tfoot id='qzwOq'></tfoot>

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