Be standards compliant when dealing with JSON serialization of NaN and Inf floats

Patch by dahla
This commit is contained in:
Latif Khalifa
2013-12-27 21:55:08 +01:00
parent 9b8c017ab9
commit 5ba075615c

View File

@@ -322,13 +322,16 @@ namespace LitJson
DoValidation (Condition.Value);
PutNewline ();
string str = Convert.ToString (number, number_format);
Put (str);
if (double.IsNaN(number) || double.IsInfinity(number))
Put("null");
else
{
string str = Convert.ToString(number, number_format);
Put(str);
if (str.IndexOf ('.') == -1 &&
str.IndexOf ('E') == -1 &&
!double.IsNaN(number))
writer.Write (".0");
if (str.IndexOf('.') == -1 && str.IndexOf('E') == -1)
writer.Write(".0");
}
context.ExpectingValue = false;
}