本文整理汇总了C#中Newtonsoft.Json.JsonTextReader.ReadAsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.ReadAsBytes方法的具体用法?C# JsonTextReader.ReadAsBytes怎么用?C# JsonTextReader.ReadAsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextReader
的用法示例。
在下文中一共展示了JsonTextReader.ReadAsBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadBytesWithBadCharacter
public void ReadBytesWithBadCharacter()
{
JsonReader reader = new JsonTextReader(new StringReader(@"true"));
reader.ReadAsBytes();
}
示例2: ReadBytesWithUnexpectedEnd
public void ReadBytesWithUnexpectedEnd()
{
string helloWorld = "Hello world!";
byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);
JsonReader reader = new JsonTextReader(new StringReader(@"'" + Convert.ToBase64String(helloWorldData)));
ExceptionAssert.Throws<JsonReaderException>(
"Unterminated string. Expected delimiter: '. Path '', line 1, position 17.",
() =>
{
reader.ReadAsBytes();
});
}
示例3: ReadBytesEmptyWrappedObject
public void ReadBytesEmptyWrappedObject()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"{}"));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Error reading bytes. Unexpected token: StartObject. Path '', line 1, position 2." );
}
示例4: ReadAsBytesIntegerArrayWithComments
public void ReadAsBytesIntegerArrayWithComments()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"[/*hi*/1/*hi*/,2/*hi*/]"));
byte[] data = reader.ReadAsBytes();
Assert.AreEqual(2, data.Length);
Assert.AreEqual(1, data[0]);
Assert.AreEqual(2, data[1]);
}
示例5: ReadAsBytesArrayWithBadContent
public void ReadAsBytesArrayWithBadContent()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"[1.0]"));
ExceptionAssert.Throws<JsonReaderException>(
"Unexpected token when reading bytes: Float. Path '[0]', line 1, position 4.",
() =>
{
reader.ReadAsBytes();
});
}
示例6: ReadSingleBytes
public void ReadSingleBytes()
{
StringReader s = new StringReader(@"""SGVsbG8gd29ybGQu""");
JsonTextReader reader = new JsonTextReader(s);
byte[] data = reader.ReadAsBytes();
Assert.IsNotNull(data);
string text = Encoding.UTF8.GetString(data, 0, data.Length);
Assert.AreEqual("Hello world.", text);
}
示例7: ReadAsBytesNoContentWrappedObject
public void ReadAsBytesNoContentWrappedObject()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"{"));
ExceptionAssert.Throws<JsonReaderException>(
"Unexpected end when reading bytes. Path '', line 1, position 1.",
() =>
{
reader.ReadAsBytes();
});
}
示例8: ReadBytesNoStartWithUnexpectedEnd
public void ReadBytesNoStartWithUnexpectedEnd()
{
JsonReader reader = new JsonTextReader(new StringReader(@"[ "));
Assert.IsTrue(reader.Read());
reader.ReadAsBytes();
}
示例9: ReadAsBytes_Base64AndGuid
public void ReadAsBytes_Base64AndGuid()
{
JsonTextReader jsonTextReader = new JsonTextReader(new StringReader("'AAAAAAAAAAAAAAAAAAAAAAAAAAABAAAA'"));
byte[] data = jsonTextReader.ReadAsBytes();
byte[] expected = Convert.FromBase64String("AAAAAAAAAAAAAAAAAAAAAAAAAAABAAAA");
CollectionAssert.AreEqual(expected, data);
jsonTextReader = new JsonTextReader(new StringReader("'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAABAAAA'"));
data = jsonTextReader.ReadAsBytes();
expected = new Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAABAAAA").ToByteArray();
CollectionAssert.AreEqual(expected, data);
}
示例10: ReadAsBytes_CommaErrors_Multiple
public void ReadAsBytes_CommaErrors_Multiple()
{
JsonTextReader reader = new JsonTextReader(new StringReader("['',,'']"));
reader.Read();
CollectionAssert.AreEquivalent(new byte[0], reader.ReadAsBytes());
ExceptionAssert.Throws<JsonReaderException>(() =>
{
reader.ReadAsBytes();
}, "Unexpected character encountered while parsing value: ,. Path '[1]', line 1, position 5.");
CollectionAssert.AreEquivalent(new byte[0], reader.ReadAsBytes());
Assert.IsTrue(reader.Read());
}
示例11: ReadBytesWithBadCharacter
public void ReadBytesWithBadCharacter()
{
JsonReader reader = new JsonTextReader(new StringReader(@"true"));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Unexpected character encountered while parsing value: t. Path '', line 1, position 1.");
}
示例12: ReadAsBytes_InvalidEndArray
public void ReadAsBytes_InvalidEndArray()
{
JsonTextReader reader = new JsonTextReader(new StringReader("]"));
ExceptionAssert.Throws<JsonReaderException>(() =>
{
reader.ReadAsBytes();
}, "Unexpected character encountered while parsing value: ]. Path '', line 1, position 1.");
}
示例13: ReadAsBytesBadContent
public void ReadAsBytesBadContent()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"new Date()"));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Unexpected character encountered while parsing value: e. Path '', line 1, position 2.");
}
示例14: ReadAsBytes_BadData
public void ReadAsBytes_BadData()
{
string json = @"pie";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
}
示例15: ReadBytesWithUnexpectedEnd
public void ReadBytesWithUnexpectedEnd()
{
string helloWorld = "Hello world!";
byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);
JsonReader reader = new JsonTextReader(new StringReader(@"'" + Convert.ToBase64String(helloWorldData)));
reader.ReadAsBytes();
}