Getting a parser error while trying to serialize an ulong array looks like the Json.NET library does not check if an integer is signed or not; Does anyone know of a workaround for this? or any other .NET Json library that can handle unsigned int?
* EDIT: code below; * It serializes perfectly, but when its deserialization causes an error; It doesn't seem to be serving an unsigned int from viewing 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:\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(); } }
source share