本文整理汇总了C#中Newtonsoft.Json.JsonReader.ReadAsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadAsBytes方法的具体用法?C# JsonReader.ReadAsBytes怎么用?C# JsonReader.ReadAsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.ReadAsBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if( reader.TokenType == JsonToken.Null )
{
return null;
}
if( reader.TokenType != JsonToken.StartObject )
{
var msg = string.Join(" ",
$"The JSON representation of binary data (byte[]) when parsing the server response is not a {Converter.PseudoTypeKey}:{Converter.Binary} object.",
$"This happens if your JSON document contains binary data (byte[]) in some other format (like a base64 string only) rather than a native RethinkDB pseudo type {Converter.PseudoTypeKey}:{Converter.Binary} object.",
$"If you are overriding the default Ser/Deserialization process, you need to make sure byte[] is a native {Converter.PseudoTypeKey}:{Converter.Binary} objects before using the built-in {nameof(ReqlBinaryConverter)}.",
"See https://rethinkdb.com/docs/data-types/ for more information about how binary data is represented in RethinkDB.");
throw new JsonSerializationException(msg);
}
reader.ReadAndAssertProperty(Converter.PseudoTypeKey);
var reql_type = reader.ReadAsString();
if( reql_type != Converter.Binary )
{
throw new JsonSerializationException($"Expected {Converter.PseudoTypeKey} should be {Converter.Binary} but got {reql_type}.");
}
reader.ReadAndAssertProperty("data");
var data = reader.ReadAsBytes();
//realign and get out of the pseudo type
//one more post read to align out of { reql_type:BINARY, data:""}
reader.ReadAndAssert();
return data;
}
示例2: Read
public IConfigureCloudQueueMessageEnvelope Read(JsonReader reader)
{
if (reader == null) throw new ArgumentNullException("reader");
IConfigureCloudQueueMessageEnvelope envelope = new CloudQueueMessageEnvelope();
reader.Read(); //StartObject
reader.Read(); //PropertyName:From
envelope = envelope.SetFrom(reader.ReadAsString()); //String:From value
reader.Read(); //PropertyName:To
envelope = envelope.SetTo(reader.ReadAsString()); //String:To value
reader.Read(); //PropertyName:MessageId
envelope = envelope.SetMessageId(new Guid(reader.ReadAsString())); //String:MessageId value
reader.Read();
if (((string)reader.Value) == "RelatesToMessageId") //PropertyName:Possibly RelatesToMessageId
{
envelope = envelope.SetRelatesToMessageId(new Guid(reader.ReadAsString()));
reader.Read(); //PropertyName:CorrelationId
}
envelope = envelope.SetCorrelationId(new Guid(reader.ReadAsString())); //String:CorrelationId value
reader.Read(); //PropertyName:ContentType
envelope = envelope.SetContentType(reader.ReadAsString()); //String:ContentType value
reader.Read(); //PropertyName:Content
envelope = envelope.SetContent(reader.ReadAsBytes()); //String:Content value
reader.Read(); //PropertyName:Time
envelope = envelope.SetTime(reader.ReadAsDateTimeOffset().GetValueOrDefault()); //String:Time value
reader.Read(); //EndObject
return envelope;
}
示例3: ReadByDataType
private static void ReadByDataType(JsonReader reader, DataType dataType)
{
switch (dataType)
{
case DataType.String:
reader.ReadAsString();
break;
case DataType.Int16:
case DataType.Int32:
reader.ReadAsInt32();
break;
case DataType.ByteArray:
reader.ReadAsBytes();
break;
case DataType.Decimal:
reader.ReadAsDecimal();
break;
case DataType.DateTime:
reader.ReadAsDateTime();
break;
// These types are dealt with, but there's no explicit reader method for them
// so we just have to trust that it does the right thing.
case DataType.Byte:
case DataType.Int64:
case DataType.Boolean:
case DataType.Float:
case DataType.Double:
reader.Read();
break;
}
}
示例4: ReadForType
private bool ReadForType(JsonReader reader, JsonContract contract, bool hasConverter)
{
if (hasConverter)
return reader.Read();
switch (contract != null ? (int) contract.InternalReadType : 0)
{
case 0:
while (reader.Read())
{
if (reader.TokenType != JsonToken.Comment)
return true;
}
return false;
case 1:
reader.ReadAsInt32();
break;
case 2:
reader.ReadAsBytes();
break;
case 3:
reader.ReadAsString();
break;
case 4:
reader.ReadAsDecimal();
break;
case 5:
reader.ReadAsDateTime();
break;
default:
throw new ArgumentOutOfRangeException();
}
return reader.TokenType != JsonToken.None;
}