當前位置: 首頁>>代碼示例>>C#>>正文


C# JsonReader.ReadAsDouble方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.JsonReader.ReadAsDouble方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonReader.ReadAsDouble方法的具體用法?C# JsonReader.ReadAsDouble怎麽用?C# JsonReader.ReadAsDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.JsonReader的用法示例。


在下文中一共展示了JsonReader.ReadAsDouble方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 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.ReadAsDouble();
            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();

            if( objectType == typeof(DateTimeOffset) ||
                objectType == typeof(DateTimeOffset?) )
            {
                return ConvertDateTimeOffset(epoch_time.Value, timezone);
            }
            else
            {
                return ConvertDateTime(epoch_time.Value, timezone, serializer.DateTimeZoneHandling);
            }
        }
開發者ID:fjsnogueira,項目名稱:RethinkDb.Driver,代碼行數:48,代碼來源:ReqlDateTimeConverter.cs

示例2: ReadJson

 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
     long value = (long)reader.ReadAsDouble().Value;
     return value.FromJsDateTime();
 }
開發者ID:XuPeiYao,項目名稱:SharpDisk,代碼行數:4,代碼來源:JsonJsDateTimeConverter.cs


注:本文中的Newtonsoft.Json.JsonReader.ReadAsDouble方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。