-Fixed reading scientific notation numbers with no decimal point
-Changed the ReadAsXXX methods to return null at the end of an array instead of throwing an error
This commit is contained in:
@@ -941,7 +941,7 @@ bye", reader.Value);
|
||||
public void ReadFloatingPointNumber()
|
||||
{
|
||||
string json =
|
||||
@"[0.0,0.0,0.1,1.0,1.000001,1E-06,4.94065645841247E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN]";
|
||||
@"[0.0,0.0,0.1,1.0,1.000001,1E-06,4.94065645841247E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN,0e-10,0.25e-5,0.3e10]";
|
||||
|
||||
using (JsonReader jsonReader = new JsonTextReader(new StringReader(json)))
|
||||
{
|
||||
@@ -1008,6 +1008,18 @@ bye", reader.Value);
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.NaN, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(0, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(0.0000025, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(3000000000, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
|
||||
}
|
||||
@@ -1933,5 +1945,73 @@ bye", reader.Value);
|
||||
Assert.IsTrue(reader.Read());
|
||||
reader.Read();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ScientificNotation()
|
||||
{
|
||||
double d;
|
||||
|
||||
d = Convert.ToDouble("6.0221418e23");
|
||||
Console.WriteLine(d.ToString(new CultureInfo("fr-FR")));
|
||||
Console.WriteLine(d.ToString("0.#############################################################################"));
|
||||
|
||||
//CultureInfo info = CultureInfo.GetCultureInfo("fr-FR");
|
||||
//Console.WriteLine(info.NumberFormat.NumberDecimalSeparator);
|
||||
|
||||
string json = @"[0e-10,0E-10,0.25e-5,0.3e10,6.0221418e23]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
reader.Read();
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(0, reader.Value);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(0, reader.Value);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(0.0000025, reader.Value);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(3000000000, reader.Value);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(602214180000000000000000d, reader.Value);
|
||||
|
||||
reader.Read();
|
||||
|
||||
|
||||
reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
reader.Read();
|
||||
|
||||
reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(0, reader.Value);
|
||||
|
||||
reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(0, reader.Value);
|
||||
|
||||
reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(0.0000025, reader.Value);
|
||||
|
||||
reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(3000000000, reader.Value);
|
||||
|
||||
reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(602214180000000000000000m, reader.Value);
|
||||
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("James", reader.Value.ToString());
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
Assert.AreEqual(typeof (string), reader.ValueType);
|
||||
Assert.AreEqual('"', reader.QuoteChar);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
@@ -302,7 +302,7 @@ namespace Newtonsoft.Json.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 10 exceeds maximum value of 5. Line 1, position 2.")]
|
||||
[ExpectedException(typeof (JsonSchemaException), ExpectedMessage = "Integer 10 exceeds maximum value of 5. Line 1, position 2.")]
|
||||
public void ThrowExceptionWhenNoValidationEventHandler()
|
||||
{
|
||||
string schemaJson = @"{
|
||||
@@ -597,13 +597,13 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
|
||||
Assert.AreEqual(@"Value false is not defined in enum. Line 1, position 11.", validationEventArgs.Message);
|
||||
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
|
||||
Assert.IsNotNull(validationEventArgs);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ArrayCountGreaterThanMaximumItems()
|
||||
{
|
||||
@@ -887,7 +887,11 @@ namespace Newtonsoft.Json.Tests
|
||||
Json.Schema.ValidationEventArgs validationEventArgs = null;
|
||||
|
||||
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
|
||||
reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; errors.Add(validationEventArgs.Message); };
|
||||
reader.ValidationEventHandler += (sender, args) =>
|
||||
{
|
||||
validationEventArgs = args;
|
||||
errors.Add(validationEventArgs.Message);
|
||||
};
|
||||
reader.Schema = JsonSchema.Parse(schemaJson);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
@@ -1175,7 +1179,11 @@ namespace Newtonsoft.Json.Tests
|
||||
List<string> errors = new List<string>();
|
||||
|
||||
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
|
||||
reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; errors.Add(validationEventArgs.Message); };
|
||||
reader.ValidationEventHandler += (sender, args) =>
|
||||
{
|
||||
validationEventArgs = args;
|
||||
errors.Add(validationEventArgs.Message);
|
||||
};
|
||||
reader.Schema = secondSchema;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
@@ -1232,7 +1240,7 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.AreEqual("three", reader.Value.ToString());
|
||||
Assert.AreEqual(5, errors.Count);
|
||||
Assert.AreEqual("String 'three' is less than minimum length of 6. Line 6, position 25.", errors[4]);
|
||||
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
|
||||
@@ -1380,57 +1388,70 @@ namespace Newtonsoft.Json.Tests
|
||||
[Test]
|
||||
public void ReadAsInt32()
|
||||
{
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (int));
|
||||
|
||||
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1")))
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
int? i = reader.ReadAsInt32();
|
||||
|
||||
Assert.AreEqual(1, i);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 5 exceeds maximum value of 2. Line 1, position 1.")]
|
||||
[ExpectedException(typeof (JsonSchemaException), ExpectedMessage = "Integer 5 exceeds maximum value of 2. Line 1, position 1.")]
|
||||
public void ReadAsInt32Failure()
|
||||
{
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (int));
|
||||
s.Maximum = 2;
|
||||
|
||||
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5")))
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
reader.ReadAsInt32();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAsDecimal()
|
||||
{
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (decimal));
|
||||
|
||||
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1.5")))
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
decimal? d = reader.ReadAsDecimal();
|
||||
|
||||
Assert.AreEqual(1.5, d);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Float 5.5 is not evenly divisible by 1. Line 1, position 3.")]
|
||||
[ExpectedException(typeof (JsonSchemaException), ExpectedMessage = "Float 5.5 is not evenly divisible by 1. Line 1, position 3.")]
|
||||
public void ReadAsDecimalFailure()
|
||||
{
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
|
||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (decimal));
|
||||
s.DivisibleBy = 1;
|
||||
|
||||
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5.5")))
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
{
|
||||
Schema = s
|
||||
};
|
||||
reader.ReadAsDecimal();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAsInt32FromSerializer()
|
||||
{
|
||||
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader("[1,2,3]")));
|
||||
reader.Schema = new JsonSchemaGenerator().Generate(typeof(int[]));
|
||||
int[] values = new JsonSerializer().Deserialize<int[]>(reader);
|
||||
|
||||
Assert.AreEqual(3, values.Length);
|
||||
Assert.AreEqual(1, values[0]);
|
||||
Assert.AreEqual(2, values[1]);
|
||||
Assert.AreEqual(3, values[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,5 +72,5 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.0.8.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("4.0.8.14611")]
|
||||
[assembly: AssemblyFileVersion("4.0.8.14618")]
|
||||
#endif
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Newtonsoft.Json.Bson
|
||||
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.
|
||||
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null. This method will return <c>null</c> at the end of an array.
|
||||
/// </returns>
|
||||
public override byte[] ReadAsBytes()
|
||||
{
|
||||
@@ -195,7 +195,7 @@ namespace Newtonsoft.Json.Bson
|
||||
if (TokenType == JsonToken.Bytes)
|
||||
return (byte[])Value;
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading bytes. Expected bytes but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -228,7 +228,7 @@ namespace Newtonsoft.Json.Bson
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Decimal}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override decimal? ReadAsDecimal()
|
||||
{
|
||||
Read();
|
||||
@@ -256,7 +256,7 @@ namespace Newtonsoft.Json.Bson
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading decimal. Expected a number but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -265,7 +265,7 @@ namespace Newtonsoft.Json.Bson
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Int32}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override int? ReadAsInt32()
|
||||
{
|
||||
Read();
|
||||
@@ -293,7 +293,7 @@ namespace Newtonsoft.Json.Bson
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading integer. Expected a number but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -304,7 +304,7 @@ namespace Newtonsoft.Json.Bson
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{DateTimeOffset}"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="Nullable{DateTimeOffset}"/>.
|
||||
/// A <see cref="Nullable{DateTimeOffset}"/>. This method will return <c>null</c> at the end of an array.
|
||||
/// </returns>
|
||||
public override DateTimeOffset? ReadAsDateTimeOffset()
|
||||
{
|
||||
@@ -333,7 +333,7 @@ namespace Newtonsoft.Json.Bson
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading date. Expected date but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
|
||||
@@ -102,14 +102,8 @@ namespace Newtonsoft.Json
|
||||
private char _quoteChar;
|
||||
internal State _currentState;
|
||||
private JTokenType _currentTypeContext;
|
||||
private bool _serializerInArray;
|
||||
private CultureInfo _culture;
|
||||
|
||||
internal void SetSerializeInArray(bool serializerInArray)
|
||||
{
|
||||
_serializerInArray = serializerInArray;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current reader state.
|
||||
/// </summary>
|
||||
@@ -235,26 +229,26 @@ namespace Newtonsoft.Json
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Int32}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public abstract int? ReadAsInt32();
|
||||
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.</returns>
|
||||
/// <returns>A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public abstract byte[] ReadAsBytes();
|
||||
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Decimal}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public abstract decimal? ReadAsDecimal();
|
||||
|
||||
#if !NET20
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{DateTimeOffset}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{DateTimeOffset}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{DateTimeOffset}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public abstract DateTimeOffset? ReadAsDateTimeOffset();
|
||||
#endif
|
||||
|
||||
@@ -434,11 +428,6 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ReaderIsSerializerInArray()
|
||||
{
|
||||
return (TokenType == JsonToken.EndArray && _serializerInArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
|
||||
@@ -362,7 +362,7 @@ namespace Newtonsoft.Json
|
||||
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.
|
||||
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null. This method will return <c>null</c> at the end of an array.
|
||||
/// </returns>
|
||||
public override byte[] ReadAsBytes()
|
||||
{
|
||||
@@ -414,7 +414,7 @@ namespace Newtonsoft.Json
|
||||
throw CreateReaderException(this, "Unexpected end when reading bytes.");
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Unexpected token when reading bytes: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -423,7 +423,7 @@ namespace Newtonsoft.Json
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Decimal}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override decimal? ReadAsDecimal()
|
||||
{
|
||||
_readType = ReadType.ReadAsDecimal;
|
||||
@@ -454,7 +454,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Unexpected token when reading decimal: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -463,7 +463,7 @@ namespace Newtonsoft.Json
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Int32}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override int? ReadAsInt32()
|
||||
{
|
||||
_readType = ReadType.ReadAsInt32;
|
||||
@@ -494,7 +494,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Unexpected token when reading integer: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -504,7 +504,7 @@ namespace Newtonsoft.Json
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{DateTimeOffset}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="DateTimeOffset"/>.</returns>
|
||||
/// <returns>A <see cref="DateTimeOffset"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override DateTimeOffset? ReadAsDateTimeOffset()
|
||||
{
|
||||
_readType = ReadType.ReadAsDateTimeOffset;
|
||||
@@ -535,7 +535,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Unexpected token when reading date: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -1270,7 +1270,10 @@ namespace Newtonsoft.Json
|
||||
JsonToken numberType;
|
||||
|
||||
bool singleDigit = (char.IsDigit(firstChar) && _stringReference.Length == 1);
|
||||
bool nonBase10 = (firstChar == '0' && _stringReference.Length > 1 && _stringReference.Chars[_stringReference.StartIndex + 1] != '.');
|
||||
bool nonBase10 = (firstChar == '0' && _stringReference.Length > 1
|
||||
&& _stringReference.Chars[_stringReference.StartIndex + 1] != '.'
|
||||
&& _stringReference.Chars[_stringReference.StartIndex + 1] != 'e'
|
||||
&& _stringReference.Chars[_stringReference.StartIndex + 1] != 'E');
|
||||
|
||||
if (_readType == ReadType.ReadAsInt32)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Newtonsoft.Json.Linq
|
||||
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.
|
||||
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null. This method will return <c>null</c> at the end of an array.
|
||||
/// </returns>
|
||||
public override byte[] ReadAsBytes()
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace Newtonsoft.Json.Linq
|
||||
if (TokenType == JsonToken.Bytes)
|
||||
return (byte[])Value;
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading bytes. Expected bytes but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -92,7 +92,7 @@ namespace Newtonsoft.Json.Linq
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Decimal}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Decimal}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override decimal? ReadAsDecimal()
|
||||
{
|
||||
Read();
|
||||
@@ -120,7 +120,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading decimal. Expected a number but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -129,7 +129,7 @@ namespace Newtonsoft.Json.Linq
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{Int32}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{Int32}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override int? ReadAsInt32()
|
||||
{
|
||||
Read();
|
||||
@@ -157,7 +157,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading integer. Expected a number but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
@@ -167,7 +167,7 @@ namespace Newtonsoft.Json.Linq
|
||||
/// <summary>
|
||||
/// Reads the next JSON token from the stream as a <see cref="Nullable{DateTimeOffset}"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Nullable{DateTimeOffset}"/>.</returns>
|
||||
/// <returns>A <see cref="Nullable{DateTimeOffset}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||
public override DateTimeOffset? ReadAsDateTimeOffset()
|
||||
{
|
||||
Read();
|
||||
@@ -194,8 +194,8 @@ namespace Newtonsoft.Json.Linq
|
||||
throw CreateReaderException(this, "Could not convert string to DateTimeOffset: {0}.".FormatWith(CultureInfo.InvariantCulture, Value));
|
||||
}
|
||||
}
|
||||
|
||||
if (ReaderIsSerializerInArray())
|
||||
|
||||
if (TokenType == JsonToken.EndArray)
|
||||
return null;
|
||||
|
||||
throw CreateReaderException(this, "Error reading date. Expected date but got {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
||||
|
||||
@@ -85,7 +85,7 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.0.8.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("4.0.8.14611")]
|
||||
[assembly: AssemblyFileVersion("4.0.8.14618")]
|
||||
#endif
|
||||
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
@@ -1093,12 +1093,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
return propertyValues;
|
||||
}
|
||||
|
||||
private void SetSerializeInArray(JsonReader reader, bool inArray, bool enable)
|
||||
{
|
||||
if (inArray)
|
||||
reader.SetSerializeInArray(enable);
|
||||
}
|
||||
|
||||
private bool ReadForType(JsonReader reader, JsonContract contract, bool hasConverter, bool inArray)
|
||||
{
|
||||
// don't read properties with converters as a specific value
|
||||
@@ -1119,29 +1113,17 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
return true;
|
||||
case ReadType.ReadAsInt32:
|
||||
SetSerializeInArray(reader, inArray, true);
|
||||
reader.ReadAsInt32();
|
||||
SetSerializeInArray(reader, inArray, false);
|
||||
|
||||
return true;
|
||||
case ReadType.ReadAsDecimal:
|
||||
SetSerializeInArray(reader, inArray, true);
|
||||
reader.ReadAsDecimal();
|
||||
SetSerializeInArray(reader, inArray, false);
|
||||
|
||||
return true;
|
||||
case ReadType.ReadAsBytes:
|
||||
SetSerializeInArray(reader, inArray, true);
|
||||
reader.ReadAsBytes();
|
||||
SetSerializeInArray(reader, inArray, false);
|
||||
|
||||
return true;
|
||||
#if !NET20
|
||||
case ReadType.ReadAsDateTimeOffset:
|
||||
SetSerializeInArray(reader, inArray, true);
|
||||
reader.ReadAsDateTimeOffset();
|
||||
SetSerializeInArray(reader, inArray, false);
|
||||
|
||||
return true;
|
||||
#endif
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user