本文整理汇总了C#中Newtonsoft.Json.JsonReader.ReadAsDecimal方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadAsDecimal方法的具体用法?C# JsonReader.ReadAsDecimal怎么用?C# JsonReader.ReadAsDecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.ReadAsDecimal方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var extent = (Extent)existingValue;
decimal? d;
d = reader.ReadAsDecimal();
d = reader.ReadAsDecimal();
d = reader.ReadAsDecimal();
d = reader.ReadAsDecimal();
return existingValue;
}
示例2: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
// Read [0.5128,0.4147] -> new Xy(0.5128, 0.4147)
var x = (float)reader.ReadAsDecimal();
var y = (float)reader.ReadAsDecimal();
// Skip Array end.
reader.Read();
return new Xy(x, y);
}
示例3: ReadJson
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The <see cref="Newtonsoft.Json.JsonReader"/> to read from.</param>
/// <param name="objectType">The <see cref="System.Type"/> of the object.</param>
/// <param name="existingValue">The existing value of object being read.</param>
/// <param name="serializer">The calling serializer.</param>
/// <returns>The object value.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
switch(reader.TokenType)
{
case JsonToken.Integer:
return new Contributors { Id = (long)reader.Value };
case JsonToken.StartObject:
reader.Read();
var value = new Contributors();
while(reader.TokenType != JsonToken.EndObject)
{
if(reader.TokenType != JsonToken.PropertyName)
throw new FormatException("The format of this object is wrong");
switch((string)reader.Value)
{
case "id":
value.Id = (long)reader.ReadAsDecimal();
break;
case "screen_name":
value.ScreenName = reader.ReadAsString();
break;
default:
reader.Read();
break;
}
reader.Read();
}
return value;
}
throw new InvalidOperationException("This object is not a Contributors");
}
示例4: 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;
}
}
示例5: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if( reader.TokenType != JsonToken.StartObject )
{
var msg = string.Join(" ",
$"The JSON representation of a DateTime/DateTimeOffset when parsing the server response is not a {Converter.PseudoTypeKey}:{Converter.Time} object.",
$"This happens if your JSON document contains DateTime/DateTimeOffsets in some other format (like an ISO8601 string) rather than a native RethinkDB pseudo type {Converter.PseudoTypeKey}:{Converter.Time} object.",
$"If you are overriding the default Ser/Deserialization process, you need to make sure DateTime/DateTimeOffset are native {Converter.PseudoTypeKey}:{Converter.Time} objects before using the built-in {nameof(ReqlDateTimeConverter)}.",
"See https://rethinkdb.com/docs/data-types/ for more information about how Date and Times are represented in RethinkDB.");
throw new JsonSerializationException(msg);
}
reader.ReadAndAssertProperty(Converter.PseudoTypeKey);
var reql_type = reader.ReadAsString();
if( reql_type != Converter.Time )
{
throw new JsonSerializationException($"Expected {Converter.PseudoTypeKey} should be {Converter.Time} but got {reql_type}.");
}
reader.ReadAndAssertProperty("epoch_time");
var epoch_time = reader.ReadAsDecimal();
if( epoch_time == null )
{
throw new JsonSerializationException($"The {Converter.PseudoTypeKey}:{Converter.Time} object doesn't have an epoch_time value.");
}
reader.ReadAndAssertProperty("timezone");
var timezone = reader.ReadAsString();
//realign and get out of the pseudo type
//one more post read to align out of { reql_type:TIME, .... }
reader.ReadAndAssert();
var tz = TimeSpan.Parse(timezone.Substring(1));
if( !timezone.StartsWith("+") )
tz = -tz;
var epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
var dt = epoch + TimeSpan.FromSeconds(Convert.ToDouble(epoch_time.Value));
var dto = dt.ToOffset(tz);
if( objectType == typeof(DateTimeOffset) )
return dto;
var tzHandle = serializer.DateTimeZoneHandling;
switch( tzHandle )
{
case DateTimeZoneHandling.Local:
return dto.LocalDateTime;
case DateTimeZoneHandling.Utc:
return dto.UtcDateTime;
case DateTimeZoneHandling.Unspecified:
return dto.DateTime;
case DateTimeZoneHandling.RoundtripKind:
return dto.Offset == TimeSpan.Zero ? dto.UtcDateTime : dto.LocalDateTime;
default:
throw new JsonSerializationException("Invalid date time handling value.");
}
}
示例6: 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;
}
示例7: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
List<Vector3> points = new List<Vector3>();
reader.Read();
int seed = (int)reader.ReadAsInt32();
reader.Read();
reader.Read();
reader.Read();
while (reader.TokenType != JsonToken.EndArray)
{
float x = (float)reader.ReadAsDecimal();
float y = (float)reader.ReadAsDecimal();
float z = (float)reader.ReadAsDecimal();
points.Add(new Vector3(x, y, z));
reader.Read();
reader.Read();
}
reader.Read();
return new PointSet(points.ToArray(), seed);
}