当前位置: 首页>>代码示例>>C#>>正文


C# JsonReader.Read方法代码示例

本文整理汇总了C#中Newtonsoft.Json.JsonReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Read方法的具体用法?C# JsonReader.Read怎么用?C# JsonReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.JsonReader的用法示例。


在下文中一共展示了JsonReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InternalReadJson

 private static object InternalReadJson(JsonReader reader, JsonSerializer serializer)
 {
     if (reader.TokenType != JsonToken.StartObject)
         throw new ArgumentException("Expected token '{' not found.");
     reader.Read();
     AttributesTable attributesTable = new AttributesTable();
     while (reader.TokenType == JsonToken.PropertyName)
     {
         string attributeName = (string) reader.Value;
         reader.Read();
         object attributeValue;
         if (reader.TokenType == JsonToken.StartObject)
         {
             // inner object
             attributeValue = InternalReadJson(reader, serializer);
         }
         else
         {
             attributeValue = reader.Value;
         }
         reader.Read();
         attributesTable.AddAttribute(attributeName, attributeValue);
     }            
     return attributesTable;
 }
开发者ID:ste10k41,项目名称:nettopologysuite,代码行数:25,代码来源:AttributesTableConverter.cs

示例2: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.String)
            {
                var ret = LogLevel.FromString((string)reader.Value);
                return ret;
            }
            else if (reader.TokenType == JsonToken.StartObject)
            {
                reader.Read();
                if (reader.TokenType == JsonToken.PropertyName && String.Equals((string)reader.Value, "name", StringComparison.OrdinalIgnoreCase))
                {
                    reader.Read();
                    if (reader.TokenType == JsonToken.String)
                    {
                        string val = (string)reader.Value;
                        reader.Read();
                        Debug.Assert(reader.TokenType == JsonToken.EndObject);
                        return LogLevel.FromString(val);
                    }
                }
            }
            return null;

        }
开发者ID:henrycomein,项目名称:NuGetGallery,代码行数:25,代码来源:LogLevelConverter.cs

示例3: ProcessToken

        private object ProcessToken(JsonReader reader)
        {
            // Recursively processes a token. This is required for elements that next other elements.
            object processedObject = null;
            if (reader.TokenType == JsonToken.StartObject)
            {
                Dictionary<string, object> dictionaryValue = new Dictionary<string, object>();
                while (reader.Read() && reader.TokenType != JsonToken.EndObject)
                {
                    string elementKey = reader.Value.ToString();
                    reader.Read();
                    dictionaryValue.Add(elementKey, ProcessToken(reader));
                }

                processedObject = dictionaryValue;
            }
            else if (reader.TokenType == JsonToken.StartArray)
            {
                List<object> arrayValue = new List<object>();
                while (reader.Read() && reader.TokenType != JsonToken.EndArray)
                {
                    arrayValue.Add(ProcessToken(reader));
                }

                processedObject = arrayValue.ToArray();
            }
            else
            {
                processedObject = reader.Value;
            }

            return processedObject;
        }
开发者ID:epall,项目名称:selenium,代码行数:33,代码来源:ResponseValueJsonConverter.cs

示例4: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            FunctionInputOutput functionInputOutput = new FunctionInputOutput();
            int startingDepth = reader.Depth;

            while (!(reader.TokenType == JsonToken.EndObject && reader.Depth == startingDepth))
            {
                reader.Read();
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    string propertyName = reader.Value.ToString();

                    if (String.Equals(propertyName, "name"))
                    {
                        reader.Read();
                        functionInputOutput.Name = reader.Value.ToString();
                    }
                    else if (String.Equals(propertyName, "type"))
                    {
                        reader.Read();
                        functionInputOutput.Type = reader.Value.ToString();
                    }
                }
            }

            return functionInputOutput;
        }
开发者ID:TrekDev,项目名称:EthClient.NET,代码行数:27,代码来源:FunctionInputOutputConverter.cs

示例5: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            List<Sex> result = new List<Sex> ();

            // now tokentype is [

            reader.Read ();

            while (reader.TokenType == JsonToken.String)
            {
                string enumString = (string)reader.Value;

                switch (enumString)
                {
                case "man":
                    result.Add (Sex.Male);
                    break;
                case "woman":
                    result.Add (Sex.Female);
                    break;
                default:
                    throw new Exception ("Wrong sex");
                }

                reader.Read ();
            }

            return result;
        }
开发者ID:welb-studio,项目名称:ClothesAndWeather,代码行数:29,代码来源:SexEnumConverter.cs

示例6: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return null;
            }

            if (reader.TokenType != JsonToken.StartArray)
            {
                return null;
            }
            reader.Read();
            var coords = new double[2];
            for (int i = 0; i < 2; ++i)
            {
                if (reader.TokenType == JsonToken.Float)
                {
                    coords[i] = (double)reader.Value;
                    reader.Read();
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    coords[i] = (double)((long)reader.Value);
                    reader.Read();
                }
            }

            var latitude = coords[0];
            var longitude = coords[1];

            return new TwitterGeoLocation.GeoCoordinates { Latitude = latitude, Longitude = longitude };
        }
开发者ID:RobertChrist,项目名称:tweetsharp,代码行数:32,代码来源:TwitterGeoConverter.cs

示例7: ReadArray

        private TypeReference[] ReadArray(JsonReader reader)
        {
            var singleItem = ReadItem(reader);
            if (singleItem != null)
            {
                return new[] { singleItem };
            }

            if (reader.TokenType != JsonToken.StartArray)
            {
                throw new ArgumentException("Unexpected token type " + reader.TokenType);
            }

            var tokens = new List<TypeReference>();
            reader.Read();
            while (reader.TokenType != JsonToken.EndArray)
            {
                singleItem = ReadItem(reader);
                if (singleItem != null)
                {
                    tokens.Add(singleItem);
                    reader.Read();
                    continue;
                }

                throw new ArgumentException("Unexpected token type " + reader.TokenType);
            }

            return tokens.ToArray();
        }
开发者ID:lokeuei,项目名称:glTF,代码行数:30,代码来源:DictionaryOfTypeReferencesConverter.cs

示例8: ReadId

 private static long ReadId(JsonReader reader)
 {
     reader.Read();
     long type = (long)reader.Value;
     reader.Read();
     return type;
 }
开发者ID:nishantsgs,项目名称:NetTopologySuite,代码行数:7,代码来源:TopoObjectConverter.cs

示例9: ReadJson

 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
   if (ReflectionUtils.IsNullableType(objectType))
     Nullable.GetUnderlyingType(objectType);
   if (reader.TokenType == JsonToken.Null)
   {
     if (!ReflectionUtils.IsNullable(objectType))
       throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Cannot convert null value to {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) objectType));
     else
       return (object) null;
   }
   else
   {
     if (reader.TokenType != JsonToken.StartConstructor || !string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
       throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token or value when parsing date. Token: {0}, Value: {1}", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType, reader.Value));
     reader.Read();
     if (reader.TokenType != JsonToken.Integer)
       throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token parsing date. Expected Integer, got {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType));
     DateTime dateTime = JsonConvert.ConvertJavaScriptTicksToDateTime((long) reader.Value);
     reader.Read();
     if (reader.TokenType != JsonToken.EndConstructor)
       throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token parsing date. Expected EndConstructor, got {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType));
     else
       return (object) dateTime;
   }
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:26,代码来源:JavaScriptDateTimeConverter.cs

示例10: ReadType

 private static string ReadType(JsonReader reader)
 {
     reader.Read();
     string type = (string)reader.Value;
     reader.Read();
     return type;
 }
开发者ID:ste10k41,项目名称:nettopologysuite,代码行数:7,代码来源:TopoObjectConverter.cs

示例11: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.StartObject)
                throw new JsonException("Expected {");

            var results = new List<InputAlias>();

            reader.Read();
            while (reader.TokenType != JsonToken.EndObject)
            {
                if (reader.TokenType != JsonToken.PropertyName)
                    throw new JsonException("Expected property name");

                var alias = (string)reader.Value;
                reader.Read();

                if (reader.TokenType != JsonToken.String)
                    throw new JsonException("Expected string");

                var value = (string)reader.Value;

                results.Add(new InputAlias
                {
                    Name = alias,
                    Value = value
                });

                reader.Read();
            }

            return results.ToArray();
        }
开发者ID:deftflux,项目名称:descent-glovepie,代码行数:32,代码来源:InputAliasesConverter.cs

示例12: 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;
 }
开发者ID:BitTacklr,项目名称:CloudQueueBus,代码行数:27,代码来源:CloudQueueMessageEnvelopeJsonReader.cs

示例13: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var itemType = objectType.GenericTypeArguments.Single();
            if (reader.TokenType == JsonToken.StartObject)
            {
                object itemsArray = null;
                LimitsReturned limitsReturned = null;
                while (reader.Read())
                {
                    if (reader.TokenType == JsonToken.StartArray)
                    {
                        //Items Array
                        itemsArray = serializer.Deserialize(reader, itemType.MakeArrayType());
                    }
                    else if (reader.TokenType == JsonToken.PropertyName && ((string)reader.Value).Equals("limits", StringComparison.OrdinalIgnoreCase))
                    {
                        reader.Read();
                        limitsReturned = serializer.Deserialize<LimitsReturned>(reader);
                    }
                }
                if (limitsReturned == null)
                {
                    throw new InvalidOperationException("Limits nicht gefunden!");
                }

                return Activator.CreateInstance(objectType, itemsArray, limitsReturned);
            }
            throw new InvalidOperationException("Der JsonReader muss auf einem Objekt stehen!");
        }
开发者ID:mjeanrichard,项目名称:XBMC-Net-Library,代码行数:29,代码来源:ItemListConverter.cs

示例14: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            EthSolidityContract contract = new EthSolidityContract();
            int startingDepth = reader.Depth;

            while (!(reader.TokenType == JsonToken.EndObject && reader.Depth == startingDepth))
            {
                reader.Read();
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    string propertyName = reader.Value.ToString();

                    if (String.Equals(propertyName, "code"))
                    {
                        reader.Read();
                        contract.Code = serializer.Deserialize<byte[]>(reader);
                    }
                    else if (String.Equals(propertyName, "info"))
                    {
                        reader.Read();
                        contract.Info = serializer.Deserialize<ContractInfo>(reader);
                    }
                    else
                    {
                        contract.ContractName = reader.Value.ToString();
                        reader.Read();
                    }
                }
            }

            return contract;
        }
开发者ID:TrekDev,项目名称:EthClient.NET,代码行数:32,代码来源:EthSolidityContractConverter.cs

示例15: ReadObject

        private object ReadObject(JsonReader reader)
        {
            var obj = new Dictionary<string, object>();

            while (reader.Read())
            {
                switch (reader.TokenType)
                {
                    case JsonToken.PropertyName:
                        var propertyName = reader.Value.ToString();

                        if (!reader.Read())
                        {
                            throw new JsonSerializationException("Unexpected end when reading IDictionary<string, object>");
                        }

                        var value = ReadValue(reader);
                        obj[propertyName] = value;
                        break;
                    case JsonToken.Comment:
                        break;
                    case JsonToken.EndObject:
                        return obj;
                }
            }

            throw new JsonSerializationException("Unexpected end when reading IDictionary<string, object>");
        }
开发者ID:cmatskas,项目名称:azure-webjobs-sdk-script,代码行数:28,代码来源:DictionaryJsonConverter.cs


注:本文中的Newtonsoft.Json.JsonReader.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。