-Added CheckAdditionalContent to JsonSerializer/JsonSerializerSettings

-Fixed bad JSON in an array with error handling creating an infinite loop
-JsonTextReader no longer returns no content after consecutive underlying content read failures
This commit is contained in:
James Newton-King
2012-05-17 15:27:26 +12:00
parent e47a0eab58
commit bdc73900b5
12 changed files with 182 additions and 79 deletions
+4 -10
View File
@@ -918,17 +918,11 @@ namespace Newtonsoft.Json
StringReader sr = new StringReader(value);
JsonSerializer jsonSerializer = JsonSerializer.Create(settings);
object deserializedValue;
// by default DeserializeObject should check for additional content
if (!jsonSerializer.IsCheckAdditionalContentSet())
jsonSerializer.CheckAdditionalContent = true;
using (JsonReader jsonReader = new JsonTextReader(sr))
{
deserializedValue = jsonSerializer.Deserialize(jsonReader, type);
if (jsonReader.Read() && jsonReader.TokenType != JsonToken.Comment)
throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object.");
}
return deserializedValue;
return jsonSerializer.Deserialize(new JsonTextReader(sr), type);
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)