<legend id='92obZ'><style id='92obZ'><dir id='92obZ'><q id='92obZ'></q></dir></style></legend>

      <bdo id='92obZ'></bdo><ul id='92obZ'></ul>

  1. <tfoot id='92obZ'></tfoot>

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

    <small id='92obZ'></small><noframes id='92obZ'>

    1. Json.NET 不区分大小写的属性反序列化

      时间:2023-05-22

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

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

                  <tbody id='ZaqUh'></tbody>
                本文介绍了Json.NET 不区分大小写的属性反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                Json.NET 将不区分大小写的属性反序列化"列为宣传的功能之一.我已经阅读过,将首先尝试匹配指定属性的大小写,如果未找到匹配项,则执行不区分大小写的搜索.然而,这似乎不是默认行为.请参阅以下示例:

                Json.NET lists "Case-insensitive property deserialization" as one of the advertised features. I have read that an attempt will first be made to match the case of the property specified and if a match is not found a case-insensitive search is performed. This does not appear to be the default behavior however. See the following example:

                var result =
                    JsonConvert.DeserializeObject<KeyValuePair<int, string>>(
                        "{key: 123, value: "test value"}"
                    );
                
                // result is equal to: default(KeyValuePair<int, string>)
                

                如果 JSON 字符串被更改以匹配属性的大小写(Key"和Value"与key"和value"),那么一切都很好:

                If the JSON string is altered to match the case of the properties ("Key" and "Value" vs "key" and "value") then all is well:

                var result =
                    JsonConvert.DeserializeObject<KeyValuePair<int, string>>(
                        "{Key: 123, Value: "test value"}"
                    );
                
                // result is equal to: new KeyValuePair<int, string>(123, "test value")
                

                有没有办法执行不区分大小写的反序列化?

                Is there a way to perform to case-insensitive deserialization?

                推荐答案

                这是一个错误.

                不区分大小写的属性反序列化是指 Json.NET 能够将名为Key"的 JSON 属性映射到 .NET 类的Key"或key"成员.

                Case-insensitive property deserialization refers to Json.NET being able to map a JSON property with the name "Key" to either a .NET class's "Key" or "key" member.

                错误是 KeyValuePair 需要它自己的 JsonConverter 但错过了不区分大小写的映射.

                The bug is KeyValuePair requires its own JsonConverter but misses out of the case insensitive mapping.

                https://github.com/JamesNK/Newtonsoft.Json/blob/fe200fbaeb5bad3852812db1e964473e1f881d93/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs

                以它为基础,在读取 JSON 时将小写的key"和value"添加到 case 语句中.

                Use that as a base and add the lower case "key" and "value" to the case statement when reading JSON.

                这篇关于Json.NET 不区分大小写的属性反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:JSON.NET 如何删除节点 下一篇:如何以编程方式从动态 JObject 获取属性

                相关文章

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

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

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

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