本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonTextReader.ReadBytesAsStream方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.ReadBytesAsStream方法的具体用法?C# JsonTextReader.ReadBytesAsStream怎么用?C# JsonTextReader.ReadBytesAsStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.JsonTextReader
的用法示例。
在下文中一共展示了JsonTextReader.ReadBytesAsStream方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseAndValidate
private static void ParseAndValidate(string text, int expectedLength)
{
var reader = new StringReader(text);
var jsonTextReader = new JsonTextReader(reader);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.StartObject, jsonTextReader.TokenType);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.PropertyName, jsonTextReader.TokenType);
Assert.Equal("Data", jsonTextReader.Value);
var memoryStream = jsonTextReader.ReadBytesAsStream();
Assert.Equal(expectedLength, memoryStream.Length);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.PropertyName, jsonTextReader.TokenType);
Assert.Equal("Metadata", jsonTextReader.Value);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.Null, jsonTextReader.TokenType);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.EndObject, jsonTextReader.TokenType);
Assert.False(jsonTextReader.Read());
}
示例2: ReadSingleValueAsStreamShouldWork
public void ReadSingleValueAsStreamShouldWork(int size)
{
var random = new Random(size);
var buffer = new byte[size];
random.NextBytes(buffer);
var d = new Data
{
Foo = buffer
};
var jsonObj = RavenJToken.FromObject(d);
var jsonObjAsString = jsonObj.ToString();
using (var textReader = new StringReader(jsonObjAsString))
using (var jsonReader = new JsonTextReader(textReader))
{
jsonReader.Read(); // start object
jsonReader.Read(); // property name
var actual = new byte[buffer.Length];
using (var objectStream = jsonReader.ReadBytesAsStream())
{
objectStream.Read(actual, 0, actual.Length);
for (int a = 0; a < actual.Length; a++)
{
if (buffer[a] != actual[a])
{
Assert.True(false, "not equal on byte " + a);
}
}
}
}
}
示例3: ReadBytesAsStreamShouldPreserveJsonTextReaderInternalState
public void ReadBytesAsStreamShouldPreserveJsonTextReaderInternalState(int size)
{
var random = new Random(size);
var buffer = new byte[size];
var items = new Data[3];
for (int i = 0; i < 3; i++)
{
random.NextBytes(buffer);
items[i] = new Data
{
Foo = buffer.ToArray()
};
}
var jsonObj = RavenJToken.FromObject(items);
var jsonObjAsString = jsonObj.ToString();
using (var textReader = new StringReader(jsonObjAsString))
using (var jsonReader = new JsonTextReader(textReader))
{
jsonReader.Read(); //start array
jsonReader.Read();
jsonReader.Read(); // property name
var actual = new byte[buffer.Length];
buffer = items[0].Foo;
using (var objectStream = jsonReader.ReadBytesAsStream())
{
objectStream.Read(actual, 0, actual.Length);
for (int a = 0; a < actual.Length; a++)
{
if (buffer[a] != actual[a])
{
Assert.True(false, "not equal on byte " + a);
}
}
}
jsonReader.Read(); //end object
jsonReader.Read(); //start object
jsonReader.Read(); // property name
actual = jsonReader.ReadAsBytes(); // value;
buffer = items[1].Foo;
for (int a = 0; a < actual.Length; a++)
{
if (buffer[a] != actual[a])
{
Assert.True(false, "not equal on byte " + a);
}
}
jsonReader.Read(); //end object
jsonReader.Read(); //start object
jsonReader.Read(); // property name
actual = new byte[buffer.Length];
buffer = items[2].Foo;
using (var objectStream = jsonReader.ReadBytesAsStream())
{
objectStream.Read(actual, 0, actual.Length);
for (int a = 0; a < actual.Length; a++)
{
if (buffer[a] != actual[a])
{
Assert.True(false, "not equal on byte " + a);
}
}
}
jsonReader.Read(); //end object
}
}
示例4: ReadMultipleValuesAsStreamShouldWork
public void ReadMultipleValuesAsStreamShouldWork(int itemsCount, int size)
{
var random = new Random(size);
var items = new Data[itemsCount];
var buffer = new byte[size];
for (int i = 0; i < itemsCount; i++)
{
random.NextBytes(buffer);
items[i] = new Data
{
Foo = buffer.ToArray()
};
}
var jsonObj = RavenJToken.FromObject(items);
var jsonObjAsString = jsonObj.ToString();
using (var textReader = new StringReader(jsonObjAsString))
using (var jsonReader = new JsonTextReader(textReader))
{
jsonReader.Read(); // start array
for (int i = 0; i < itemsCount; i++)
{
jsonReader.Read();
jsonReader.Read(); // property name
var actual = new byte[buffer.Length];
buffer = items[i].Foo;
using (var objectStream = jsonReader.ReadBytesAsStream())
{
objectStream.Read(actual, 0, actual.Length);
//Assert.Equal(buffer, actual);
for (int a = 0; a < actual.Length; a++)
{
if (buffer[a] != actual[a])
{
Assert.True(false, "not equal on byte " + a);
}
}
}
jsonReader.Read(); //end object
}
}
}