尝试序列化ulong数组时出现解析器错误,看起来Json.NET库不检查整数是有符号还是无符号;任何人都知道解决方法吗?或任何其他可以处理unsigned int的.NET Json库?
*编辑:以下代码; *
序列化很好,但是当它反序列化时会抛出错误;看起来它不能满足unsigned int查看堆栈跟踪;
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:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonTextReader.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(); } }