public void AppendCharsWhileReadingNull() { string json = @"[ { ""$id"": ""1"", ""Name"": ""e1"", ""Manager"": null }, { ""$id"": ""2"", ""Name"": ""e2"", ""Manager"": null }, { ""$ref"": ""1"" }, { ""$ref"": ""2"" } ]"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[129]); #endif for (int i = 0; i < 15; i++) { reader.Read(); } reader.Read(); Assert.Equal(JsonToken.Null, reader.TokenType); }
public void AppendCharsWhileReadingNewLine() { string json = @" { ""description"": ""A person"", ""type"": ""object"", ""properties"": { ""name"": {""type"":""string""}, ""hobbies"": { ""type"": ""array"", ""items"": {""type"":""string""} } } } "; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[129]); #endif for (int i = 0; i < 14; i++) { Assert.True(reader.Read()); } Assert.True(reader.Read()); Assert.Equal(JsonToken.PropertyName, reader.TokenType); Assert.Equal("type", reader.Value); }
public void ParseAdditionalContent_Text() { string json = @"[ ""Small"", ""Medium"", ""Large"" ]content"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[2]); #endif reader.Read(); Assert.Equal(1, reader.LineNumber); reader.Read(); Assert.Equal(2, reader.LineNumber); reader.Read(); Assert.Equal(3, reader.LineNumber); reader.Read(); Assert.Equal(4, reader.LineNumber); reader.Read(); Assert.Equal(5, reader.LineNumber); AssertException.Throws<JsonReaderException>(() => { reader.Read(); }, "Additional text encountered after finished reading JSON content: c. Path '', line 5, position 2."); }
public void ReadingIndented() { string input = @"{ CPU: 'Intel', Drives: [ 'DVD read/writer', ""500 gigabyte hard drive"" ] }"; StringReader sr = new StringReader(input); using (JsonTextReader jsonReader = new JsonTextReader(sr)) { #if DEBUG jsonReader.SetCharBuffer(new char[5]); #endif Assert.Equal(jsonReader.TokenType, JsonToken.None); Assert.Equal(0, jsonReader.LineNumber); Assert.Equal(0, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.StartObject); Assert.Equal(1, jsonReader.LineNumber); Assert.Equal(1, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.PropertyName); Assert.Equal(jsonReader.Value, "CPU"); Assert.Equal(2, jsonReader.LineNumber); Assert.Equal(7, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(JsonToken.String, jsonReader.TokenType); Assert.Equal("Intel", jsonReader.Value); Assert.Equal(2, jsonReader.LineNumber); Assert.Equal(15, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.PropertyName); Assert.Equal(jsonReader.Value, "Drives"); Assert.Equal(3, jsonReader.LineNumber); Assert.Equal(10, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.StartArray); Assert.Equal(3, jsonReader.LineNumber); Assert.Equal(12, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.String); Assert.Equal(jsonReader.Value, "DVD read/writer"); Assert.Equal(jsonReader.QuoteChar, '\''); Assert.Equal(4, jsonReader.LineNumber); Assert.Equal(22, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.String); Assert.Equal(jsonReader.Value, "500 gigabyte hard drive"); Assert.Equal(jsonReader.QuoteChar, '"'); Assert.Equal(5, jsonReader.LineNumber); Assert.Equal(30, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.EndArray); Assert.Equal(6, jsonReader.LineNumber); Assert.Equal(4, jsonReader.LinePosition); jsonReader.Read(); Assert.Equal(jsonReader.TokenType, JsonToken.EndObject); Assert.Equal(7, jsonReader.LineNumber); Assert.Equal(2, jsonReader.LinePosition); Assert.False(jsonReader.Read()); } }
public void ParseNullStringConstructor() { string json = "new Date\0()"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[7]); #endif Assert.True(reader.Read()); Assert.Equal("Date", reader.Value); Assert.Equal(JsonToken.StartConstructor, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(JsonToken.EndConstructor, reader.TokenType); }
public void ReadBufferOnEndComment() { string json = @"/*comment*/ { /*comment*/ ""Name"": /*comment*/ ""Apple"" /*comment*/, /*comment*/ ""ExpiryDate"": ""\/Date(1230422400000)\/"", ""Price"": 3.99, ""Sizes"": /*comment*/ [ /*comment*/ ""Small"", /*comment*/ ""Medium"" /*comment*/, /*comment*/ ""Large"" /*comment*/ ] /*comment*/ } /*comment*/"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[5]); #endif for (int i = 0; i < 26; i++) { Assert.True(reader.Read()); } Assert.True(reader.Read()); Assert.Equal(JsonToken.Comment, reader.TokenType); Assert.False(reader.Read()); }
public void ReadBufferOnControlChar() { string json = @"[ { ""Name"": ""Jim"", ""BirthDate"": ""\/Date(978048000000)\/"", ""LastModified"": ""\/Date(978048000000)\/"" }, { ""Name"": ""Jim"", ""BirthDate"": ""\/Date(978048000000)\/"", ""LastModified"": ""\/Date(978048000000)\/"" } ]"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[5]); #endif for (int i = 0; i < 13; i++) { reader.Read(); } Assert.True(reader.Read()); Assert.Equal(new DateTime(631136448000000000), reader.Value); }
public void ReadUnicode() { string json = @"{""Message"":""Hi,I\u0092ve send you smth""}"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[5]); #endif Assert.True(reader.Read()); Assert.Equal(JsonToken.StartObject, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(JsonToken.PropertyName, reader.TokenType); Assert.Equal("Message", reader.Value); Assert.True(reader.Read()); Assert.Equal(JsonToken.String, reader.TokenType); Assert.Equal(@"Hi,I" + '\u0092' + "ve send you smth", reader.Value); Assert.True(reader.Read()); Assert.Equal(JsonToken.EndObject, reader.TokenType); Assert.False(reader.Read()); }
public void EscapedUnicodeText() { string json = @"[""\u003c"",""\u5f20""]"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); #if DEBUG reader.SetCharBuffer(new char[2]); #endif reader.Read(); Assert.Equal(JsonToken.StartArray, reader.TokenType); reader.Read(); Assert.Equal("<", reader.Value); reader.Read(); Assert.Equal(24352, Convert.ToInt32(Convert.ToChar((string)reader.Value))); reader.Read(); Assert.Equal(JsonToken.EndArray, reader.TokenType); }