久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

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

      使用帶有 ItemRequired = Required.Always 的 Json.Net 反序

      Ignore a property when deserializing using Json.Net with ItemRequired = Required.Always(使用帶有 ItemRequired = Required.Always 的 Json.Net 反序列化時忽略屬性)
        <bdo id='rxmEp'></bdo><ul id='rxmEp'></ul>

            • <small id='rxmEp'></small><noframes id='rxmEp'>

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

                  <tbody id='rxmEp'></tbody>
                <tfoot id='rxmEp'></tfoot>
                本文介紹了使用帶有 ItemRequired = Required.Always 的 Json.Net 反序列化時忽略屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在使用 Json.Net 將類序列化和反序列化為 json 并返回.

                I'm using Json.Net to serialize and deserialize classes to json and back.

                我向標有 [JsonObject(ItemRequired = Required.Always)](或 Required.Always)的類添加了一個新的 get-only 屬性.這將導致以下 JsonSerializationException:

                I added to a class marked with [JsonObject(ItemRequired = Required.Always)] (or Required.Always) a new get-only property. That results in the following JsonSerializationException:

                Newtonsoft.Json.JsonSerializationException:在 JSON 中找不到必需的屬性 '<PropertyName>'

                Newtonsoft.Json.JsonSerializationException: Required property '<PropertyName>' not found in JSON

                我認為用 JsonIgnore 標記該屬性可以解決問題,但這不起作用.

                I thought marking that property with JsonIgnore would solve the issue, but that doesn't work.

                我如何告訴 Json.Net 這個屬性應該被忽略?

                How can I tell Json.Net that this property should be ignored?

                這是重現問題的最小示例:

                Here's a minimal example reproducing the issue:

                [JsonObject(ItemRequired = Required.Always)]
                public class Hamster
                {
                    public string FirstName { get; set; }
                    public string LastName { get; set; }
                    [JsonIgnore]
                    public string FullName { get { return FirstName + LastName; }}
                }
                
                private static void Main()
                {
                    var hamster = new Hamster {FirstName = "Bar", LastName = "Arnon"};
                    var serializeObject = JsonConvert.SerializeObject(hamster);
                    var deserializeObject = JsonConvert.DeserializeObject<Hamster>(serializeObject);
                }
                

                推薦答案

                顯然 JsonIgnore 在這種情況下只會控制序列化.JsonIgnore 需要指定 FullName 屬性不應序列化為 json 表示形式.

                Evidently JsonIgnore will only control the serialization in this case. JsonIgnore is required to specify that the FullName property should not be serialized to the json representation.

                要在反序列化過程中忽略該屬性,我們需要添加 JsonProperty 注釋和 Required = Required.Default(表示不需要).

                To ignore the property during deserialization we need to add the JsonProperty annotation with Required = Required.Default (which means not required).

                所以,這是避免JsonSerializationException的方法:

                So, this is how to avoid the JsonSerializationException:

                [JsonObject(ItemRequired = Required.Always)]
                public class Hamster
                {
                    public string FirstName { get; set; }
                    public string LastName { get; set; }
                    [JsonIgnore]
                    [JsonProperty(Required = Required.Default)]
                    public string FullName { get { return FirstName + LastName; }}
                }
                

                這篇關于使用帶有 ItemRequired = Required.Always 的 Json.Net 反序列化時忽略屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                Parse malformed XML(解析格式錯誤的 XML)

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

                  <tbody id='OKrw2'></tbody>
              • <tfoot id='OKrw2'></tfoot>
                  <bdo id='OKrw2'></bdo><ul id='OKrw2'></ul>

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

                          主站蜘蛛池模板: 激情视频一区 | 精品少妇一区二区三区日产乱码 | 成人精品视频 | 网站黄色av | 亚洲国产一区二区视频 | 亚洲国产精品久久人人爱 | 99精品欧美一区二区蜜桃免费 | 欧美精品一区二区免费 | 亚洲欧美国产毛片在线 | 91精品国产乱码麻豆白嫩 | 亚洲一区二区 | 成人高潮片免费视频欧美 | 亚洲导航深夜福利涩涩屋 | 超碰激情 | 成人免费看电影 | 国产精品mv在线观看 | av一区二区三区四区 | 久操国产 | 久草在线在线精品观看 | 亚洲精品久久久一区二区三区 | 亚洲视频免费观看 | 毛片视频免费 | 日韩精品一区二区三区中文在线 | 亚洲久久在线 | 中文字幕在线观看第一页 | 亚洲激情综合 | 精品久久国产视频 | 亚洲一二三区不卡 | 亚洲 欧美 日韩在线 | 午夜免费观看网站 | 黄视频免费观看 | 久久久精品 | 中文字幕专区 | 一本色道久久综合亚洲精品高清 | 国产免费一区二区 | 波霸ol一区二区 | 天天看天天爽 | 亚洲bt 欧美bt 日本bt | 国产精品一区二区三区在线 | 国产亚洲一区二区精品 | 91一区二区三区 |