本文整理汇总了C#中Newtonsoft.Json.JsonTextReader.SetCharBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.SetCharBuffer方法的具体用法?C# JsonTextReader.SetCharBuffer怎么用?C# JsonTextReader.SetCharBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextReader
的用法示例。
在下文中一共展示了JsonTextReader.SetCharBuffer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendCharsWhileReadingNewLine
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.IsTrue(reader.Read());
}
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.AreEqual("type", reader.Value);
}
示例2: ReadingIndented
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.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());
}
}
示例3: AppendCharsWhileReadingNull
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.AreEqual(JsonToken.Null, reader.TokenType);
}
示例4: ParseNullStringConstructor
public void ParseNullStringConstructor()
{
string json = "new Date\0()";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[7]);
#endif
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);
}
示例5: ParseAdditionalContent_Text
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.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);
ExceptionAssert.Throws<JsonReaderException>(
"Additional text encountered after finished reading JSON content: c. Path '', line 5, position 2.",
() =>
{
reader.Read();
});
}
示例6: ReadBufferOnEndComment
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.IsTrue(reader.Read());
}
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Comment, reader.TokenType);
Assert.IsFalse(reader.Read());
}
示例7: ReadBufferOnControlChar
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.IsTrue(reader.Read());
Assert.AreEqual(new DateTime(631136448000000000), reader.Value);
}
示例8: ReadUnicode
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.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());
}
示例9: EscapedUnicodeText
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.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);
}
示例10: ParseAdditionalContent_Text
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();
}