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)); reader.SetCharBuffer(new char[129]); for (int i = 0; i < 14; i++) { Assert.IsTrue(reader.Read()); } Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.PropertyName, reader.TokenType); Assert.AreEqual("type", reader.Value); }
public void EscapedUnicodeText() { string json = @"[""\u003c"",""\u5f20""]"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); reader.SetCharBuffer(new char[2]); reader.Read(); Assert.AreEqual(JsonToken.StartArray, reader.TokenType); reader.Read(); Assert.AreEqual("<", reader.Value); reader.Read(); Assert.AreEqual(24352, Convert.ToInt32(Convert.ToChar((string)reader.Value))); reader.Read(); Assert.AreEqual(JsonToken.EndArray, reader.TokenType); }
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)) { jsonReader.SetCharBuffer(new char[5]); Assert.AreEqual(jsonReader.TokenType, JsonToken.None); Assert.AreEqual(0, jsonReader.LineNumber); Assert.AreEqual(0, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.StartObject); Assert.AreEqual(1, jsonReader.LineNumber); Assert.AreEqual(1, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName); Assert.AreEqual(jsonReader.Value, "CPU"); Assert.AreEqual(2, jsonReader.LineNumber); Assert.AreEqual(7, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(JsonToken.String, jsonReader.TokenType); Assert.AreEqual("Intel", jsonReader.Value); Assert.AreEqual(2, jsonReader.LineNumber); Assert.AreEqual(15, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName); Assert.AreEqual(jsonReader.Value, "Drives"); Assert.AreEqual(3, jsonReader.LineNumber); Assert.AreEqual(10, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.StartArray); Assert.AreEqual(3, jsonReader.LineNumber); Assert.AreEqual(12, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.String); Assert.AreEqual(jsonReader.Value, "DVD read/writer"); Assert.AreEqual(jsonReader.QuoteChar, '\''); Assert.AreEqual(4, jsonReader.LineNumber); Assert.AreEqual(22, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.String); Assert.AreEqual(jsonReader.Value, "500 gigabyte hard drive"); Assert.AreEqual(jsonReader.QuoteChar, '"'); Assert.AreEqual(5, jsonReader.LineNumber); Assert.AreEqual(30, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray); Assert.AreEqual(6, jsonReader.LineNumber); Assert.AreEqual(4, jsonReader.LinePosition); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject); Assert.AreEqual(7, jsonReader.LineNumber); Assert.AreEqual(2, jsonReader.LinePosition); Assert.IsFalse(jsonReader.Read()); } }
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)); reader.SetCharBuffer(new char[129]); for (int i = 0; i < 15; i++) { reader.Read(); } reader.Read(); Assert.AreEqual(JsonToken.Null, reader.TokenType); }
public void ParseNullStringConstructor() { string json = "new Date\0()"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); reader.SetCharBuffer(new char[7]); Assert.IsTrue(reader.Read()); Assert.AreEqual("Date", reader.Value); Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType); Assert.IsTrue(reader.Read()); Assert.AreEqual(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)); reader.SetCharBuffer(new char[5]); for (int i = 0; i < 26; i++) { Assert.IsTrue(reader.Read()); } Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.Comment, reader.TokenType); Assert.IsFalse(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)); reader.SetCharBuffer(new char[5]); for (int i = 0; i < 13; i++) { reader.Read(); } Assert.IsTrue(reader.Read()); Assert.AreEqual(new DateTime(631136448000000000), reader.Value); }
public void ParseAdditionalContent_Text() { string json = @"[ ""Small"", ""Medium"", ""Large"" ]content"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); reader.SetCharBuffer(new char[2]); reader.Read(); Assert.AreEqual(1, reader.LineNumber); reader.Read(); Assert.AreEqual(2, reader.LineNumber); reader.Read(); Assert.AreEqual(3, reader.LineNumber); reader.Read(); Assert.AreEqual(4, reader.LineNumber); reader.Read(); Assert.AreEqual(5, reader.LineNumber); reader.Read(); }
public void ReadUnicode() { string json = @"{""Message"":""Hi,I\u0092ve send you smth""}"; JsonTextReader reader = new JsonTextReader(new StringReader(json)); reader.SetCharBuffer(new char[5]); Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.StartObject, reader.TokenType); Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.PropertyName, reader.TokenType); Assert.AreEqual("Message", reader.Value); Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.String, reader.TokenType); Assert.AreEqual(@"Hi,I" + '\u0092' + "ve send you smth", reader.Value); Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.EndObject, reader.TokenType); Assert.IsFalse(reader.Read()); }