diff --git a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs index 1c6f8369..43167e5d 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs @@ -803,6 +803,7 @@ keyword such as type of business."" o.Children()["item"].Children()["title"].Values().ToArray()); } + [Test] public void UriGuidTimeSpanTestClassEmptyTest() { UriGuidTimeSpanTestClass c1 = new UriGuidTimeSpanTestClass(); @@ -824,6 +825,7 @@ keyword such as type of business."" Assert.AreEqual(c1.Uri, c2.Uri); } + [Test] public void UriGuidTimeSpanTestClassValuesTest() { UriGuidTimeSpanTestClass c1 = new UriGuidTimeSpanTestClass @@ -851,5 +853,17 @@ keyword such as type of business."" Assert.AreEqual(c1.NullableTimeSpan, c2.NullableTimeSpan); Assert.AreEqual(c1.Uri, c2.Uri); } + + [Test] + public void ParseWithPrecendingComments() + { + string json = @"/* blah */ {'hi':'hi!'}"; + JObject o = JObject.Parse(json); + Assert.AreEqual("hi!", (string)o["hi"]); + + json = @"/* blah */ ['hi!']"; + JArray a = JArray.Parse(json); + Assert.AreEqual("hi!", (string)a[0]); + } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 1c1936a6..31cbcb0f 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -72,5 +72,5 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.5.7.15114")] +[assembly: AssemblyFileVersion("4.5.7.15115")] #endif diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs index 997157a7..949c134d 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.cs @@ -113,6 +113,12 @@ namespace Newtonsoft.Json.Linq if (!reader.Read()) throw JsonReaderException.Create(reader, "Error reading JArray from JsonReader."); } + + while (reader.TokenType == JsonToken.Comment) + { + reader.Read(); + } + if (reader.TokenType != JsonToken.StartArray) throw JsonReaderException.Create(reader, "Error reading JArray from JsonReader. Current JsonReader item is not an array: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs index fe17fc6d..bb37617b 100644 --- a/Src/Newtonsoft.Json/Linq/JConstructor.cs +++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs @@ -187,6 +187,11 @@ namespace Newtonsoft.Json.Linq throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader."); } + while (reader.TokenType == JsonToken.Comment) + { + reader.Read(); + } + if (reader.TokenType != JsonToken.StartConstructor) throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index c0316c46..0c311199 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -292,6 +292,11 @@ namespace Newtonsoft.Json.Linq throw JsonReaderException.Create(reader, "Error reading JObject from JsonReader."); } + while (reader.TokenType == JsonToken.Comment) + { + reader.Read(); + } + if (reader.TokenType != JsonToken.StartObject) { throw JsonReaderException.Create(reader, "Error reading JObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); diff --git a/Src/Newtonsoft.Json/Linq/JProperty.cs b/Src/Newtonsoft.Json/Linq/JProperty.cs index 63c4ca50..ccfba603 100644 --- a/Src/Newtonsoft.Json/Linq/JProperty.cs +++ b/Src/Newtonsoft.Json/Linq/JProperty.cs @@ -229,6 +229,12 @@ namespace Newtonsoft.Json.Linq if (!reader.Read()) throw JsonReaderException.Create(reader, "Error reading JProperty from JsonReader."); } + + while (reader.TokenType == JsonToken.Comment) + { + reader.Read(); + } + if (reader.TokenType != JsonToken.PropertyName) throw JsonReaderException.Create(reader, "Error reading JProperty from JsonReader. Current JsonReader item is not a property: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 77f85bf2..95063ac1 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -1222,7 +1222,6 @@ namespace Newtonsoft.Json.Linq if (!JsonReader.IsStartToken(reader.TokenType)) return new JValue(reader.Value); - // TODO: loading constructor and parameters? throw JsonReaderException.Create(reader, "Error reading JToken from JsonReader. Unexpected token: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 7682ed79..806bd1af 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -90,7 +90,7 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.5.7.15114")] +[assembly: AssemblyFileVersion("4.5.7.15115")] #endif [assembly: CLSCompliant(true)]