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

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

        <small id='7Jcdz'></small><noframes id='7Jcdz'>

        Json.Net PopulateObject 追加列表而不是设置值

        时间:2023-08-23

          <legend id='vHxjY'><style id='vHxjY'><dir id='vHxjY'><q id='vHxjY'></q></dir></style></legend>
          1. <tfoot id='vHxjY'></tfoot>
            • <small id='vHxjY'></small><noframes id='vHxjY'>

                <tbody id='vHxjY'></tbody>

                • <bdo id='vHxjY'></bdo><ul id='vHxjY'></ul>
                  <i id='vHxjY'><tr id='vHxjY'><dt id='vHxjY'><q id='vHxjY'><span id='vHxjY'><b id='vHxjY'><form id='vHxjY'><ins id='vHxjY'></ins><ul id='vHxjY'></ul><sub id='vHxjY'></sub></form><legend id='vHxjY'></legend><bdo id='vHxjY'><pre id='vHxjY'><center id='vHxjY'></center></pre></bdo></b><th id='vHxjY'></th></span></q></dt></tr></i><div id='vHxjY'><tfoot id='vHxjY'></tfoot><dl id='vHxjY'><fieldset id='vHxjY'></fieldset></dl></div>
                  本文介绍了Json.Net PopulateObject 追加列表而不是设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在 .Net 4.5 中使用 Json.Net,当在以下对象上使用填充对象时,它会使用 json 的内容来增加 List 的值,而不是设置它的值.

                  I am using Json.Net for .Net 4.5 and when using populate object on the following object it increments the List's with the content of the json rather than setting its value.

                  Json.Net

                  JsonConvert.PopulateObject(string, object)
                  

                  class MySettingSubClass
                  {
                      public List<string> MyStringList1 = new List<string>(){"one", "two", "three"}
                  }
                  
                  class MySetting
                  {
                      public string MyString = "MyString";
                      public int MyInt = 5;
                      public MySettingSubClass MyClassObject = new MySettingSubClass();
                      public List<string> MyStringList2 = new List<string>{"one", "two", "three"};
                  }
                  

                  当它们最初加载时,一切都是正确的,但是从 JSON 重新加载两个 MyStringLists 都是重复的 one"、two"、three"、one"、two"、three"

                  When they initially load, all is correct, however reloading from JSON both MyStringLists are duplicated "one", "two", "three", "one", "two", "three"

                  推荐答案

                  你应该告诉 Json.Net 替换数组,像这样:

                  You should tell Json.Net to replace the arrays, like this:

                  var serializerSettings = new JsonSerializerSettings {ObjectCreationHandling = ObjectCreationHandling.Replace};
                  
                  
                  JsonConvert.PopulateObject(jasonString, myObject, serializerSettings)
                  

                  这篇关于Json.Net PopulateObject 追加列表而不是设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:对象&amp;使用 JSON.Net 进行驼峰式转换 下一篇:将 JSON.NET JObject 的属性/标记转换为字典键

                  相关文章

                  最新文章

                  1. <small id='bD2Ln'></small><noframes id='bD2Ln'>

                    • <bdo id='bD2Ln'></bdo><ul id='bD2Ln'></ul>

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