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?
*EDIT: 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();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…