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

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

    2. 序列化无符号整数 (ulong) 数组时 Json.NET 崩溃

      时间:2023-05-22

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

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

                <tbody id='cdI1i'></tbody>

                <bdo id='cdI1i'></bdo><ul id='cdI1i'></ul>
                本文介绍了序列化无符号整数 (ulong) 数组时 Json.NET 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                尝试序列化 ulong 数组时出现解析器错误,看起来 Json.NET 库没有检查整数是有符号还是无符号;有人知道解决方法吗?或任何其他可以处理 unsigned int 的 .NET Json 库?

                Getting a parser error when trying to serialize a ulong array, looks like the Json.NET library isnt checking if the integer is signed or unsigned; any one know of a workaround for this? or any other .NET Json library that can handle unsigned int's?

                *代码如下;*它可以很好地序列化,但是在反序列化时会引发错误;从查看堆栈跟踪来看,它似乎不适合 unsigned int;

                * code below; * It serializes fine, but when its deserializing it throws an error; Looks like it doesnt cater for the unsigned int from looking at the stack trace;

                NewTonsoft.Json.JsonReaderException : {"JSON integer 18446744073709551615 is too large or small for an Int64."}
                
                Value was either too large or too small for an Int64.
                   at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)
                   at System.Convert.ToInt64(String value, IFormatProvider provider)
                   at Newtonsoft.Json.JsonTextReader.ParseNumber() in d:DevelopmentReleasesJsonWorkingSrcNewtonsoft.JsonJsonTextReader.cs:line 1360
                

                   class Program
                        {
                            static void Main(string[] args)
                            {
                                string output = JsonConvert.SerializeObject(new ulong[] {ulong.MinValue, 20, 21, 22, ulong.MaxValue});
                                Console.WriteLine(output);
                
                                ulong[] array = JsonConvert.DeserializeObject<ulong[]>(output);
                                Console.WriteLine(array);
                
                                Console.ReadLine();
                            }
                        }
                

                推荐答案

                没错,在这种情况下,JSON.Net 不会处理大于 long.MaxValue 的值.

                You're right, JSON.Net doesn't handle values larger than long.MaxValue in this case.

                除了修改库的源代码外,我没有找到任何修改该行为的方法.作为一种解决方法,您可以将其反序列化为 decimal[],然后将其转换为 ulong[].

                I didn't find any way to modify that behavior, except by modifying the source code of the library. As a workaround, you could deserialize it as decimal[] and then convert that into ulong[].

                这篇关于序列化无符号整数 (ulong) 数组时 Json.NET 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Json.Net在列表反序列化过程中调用属性getter,导致重复项 下一篇:得到“因为该类型需要一个 JSON 数组(例如 [1,2,3])才能正确反序列化"反序列化 Json 对象时出

                相关文章

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

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

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