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


C# Json.JsonReader类代码示例

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


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

示例1: ReadJson

		/// <summary>
		/// Reads the JSON representation of the object.
		/// </summary>
		/// <param name="reader">The <see cref="T:Raven.Imports.Newtonsoft.Json.JsonReader"/> to read from.</param>
		/// <param name="objectType">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)
		{
			var enumType = Nullable.GetUnderlyingType(objectType) ?? objectType;
			if (enumType != objectType && reader.TokenType == JsonToken.Null)//nullable
				return null;
			return Enum.Parse(enumType, reader.Value.ToString(), true);
		}
开发者ID:royra,项目名称:ravendb,代码行数:15,代码来源:JsonEnumConverter.cs

示例2: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            reader.Read();

            Debug.Assert(reader.TokenType == JsonToken.PropertyName);
            Debug.Assert((string)reader.Value == "coordinates");

            if (objectType == typeof(Coordinate))
            {
                return ReadJsonCoordinate(reader);
            }

            if (typeof(IEnumerable<Coordinate>).IsAssignableFrom(objectType))
            {
                return ReadJsonCoordinates(reader);
            }

            if (typeof(List<Coordinate[]>).IsAssignableFrom(objectType))
            {
                return ReadJsonCoordinatesEnumerable(reader);
            }
            if (typeof(List<List<Coordinate[]>>).IsAssignableFrom(objectType))
            {
                return ReadJsonCoordinatesEnumerable2(reader);
            }

            throw new Exception();
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:28,代码来源:CoordinateConverters.cs

示例3: ReadJson

 /// <summary>
 /// Reads the JSON representation of the object.
 /// </summary>
 /// <remarks>
 /// this converter will never be needed to deserialize from json -
 ///  built-in converter is enough as Json.Net serializes any collection - including IEnumerable{T} to json arrays.
 /// </remarks>
 /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="existingValue">The existing value of object being read.</param>
 /// <param name="serializer">The calling serializer.</param>
 /// <returns>executing this method will throw <see cref="NotSupportedException">NotSupportedException</see> since this converter should not be used for reading</returns>
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     //this converter will never be needed to deserialize from json - built-in converter is enough as
     //Json.Net serializes any collection - including IEnumerable<T> to json arrays.
     throw new NotSupportedException(@"JsonLinqEnumerableConverter should not be used to deserialize collections from json - 
                                     if this exception gets thrown, it is probably a bug.");
 }
开发者ID:heinnge,项目名称:ravendb,代码行数:19,代码来源:JsonLinqEnumerableConverter.cs

示例4: ReadJson

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

			return wktReader.Read((string)reader.Value);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:7,代码来源:WktConverter.cs

示例5: ReadJson

		/// <summary>
		/// Reads the JSON representation of the object.
		/// </summary>
		/// <param name="reader">The <see cref="T:Raven.Imports.Newtonsoft.Json.JsonReader"/> to read from.</param>
		/// <param name="objectType">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)
		{
			// Handle null values
			if (reader.TokenType == JsonToken.Null) return null;

			var arrayItemType = objectType.GetElementType();
			var arrayRank = objectType.GetArrayRank();

			// Retrieve all the values from the Json
			var arrayValues = ReadRank(reader, serializer, arrayItemType);

			// Determine the lengths of all ranks for the array
			var rankLengthList = GetRankLengthList(arrayValues);

			// If empty values were found, make sure the ranks match in size
			for (var i = rankLengthList.Count; i < arrayRank; i++)
			{
				rankLengthList.Add(0);
			}

			var rankLengthArray = rankLengthList.ToArray();

			// Create the array that will hold the values
			var retVal = Array.CreateInstance(arrayItemType, rankLengthArray);

			// Make the assignments
			SetValues(retVal, rankLengthArray, new int[0], 0, arrayValues);

			return retVal;
		}
开发者ID:925coder,项目名称:ravendb,代码行数:38,代码来源:JsonMultiDimensionalArrayConverter.cs

示例6: ReadJson

 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     JToken jo = JToken.Load(reader);
     System.Net.IPAddress address = jo["Address"].ToObject<System.Net.IPAddress>(serializer);
     int port = jo["Port"].Value<int>();
     return new System.Net.IPEndPoint(address, port);
 }
开发者ID:nahugrau,项目名称:RavenDBTests,代码行数:7,代码来源:IPEndpointConverter.cs

示例7: ReadJson

		/// <summary>
		/// Reads the JSON representation of the object.
		/// </summary>
		/// <param name="reader">The <see cref="T:Raven.Imports.Newtonsoft.Json.JsonReader"/> to read from.</param>
		/// <param name="objectType">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)
		{
		    var token = RavenJToken.ReadFrom(reader);
		    var val = token as RavenJValue;
		    if(val != null)
		        return val.Value;
		    var array = token as RavenJArray;
			if (array != null)
			{
				var dynamicJsonObject = new DynamicJsonObject(new RavenJObject());
				return new DynamicList(array.Select(dynamicJsonObject.TransformToValue).ToArray());
			}

			var typeName = token.Value<string>("$type");
			if(typeName != null)
			{
				var type = Type.GetType(typeName, false);
				if(type != null)
				{
					return serializer.Deserialize(new RavenJTokenReader(token), type);
				}
			}

		    return new DynamicJsonObject((RavenJObject)((RavenJObject)token).CloneToken());
		}
开发者ID:925coder,项目名称:ravendb,代码行数:33,代码来源:JsonDynamicConverter.cs

示例8: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			var collection = new NameValueCollection();

			while (reader.Read())
			{
				if (reader.TokenType == JsonToken.EndObject)
					break;

				var key = (string)reader.Value;

				if (reader.Read() == false)
					throw new InvalidOperationException("Expected PropertyName, got " + reader.TokenType);

				if (reader.TokenType == JsonToken.StartArray)
				{
					var values = serializer.Deserialize<string[]>(reader);
					foreach (var value in values)
					{
						collection.Add(key, value);
					}
				}
				else
				{
					collection.Add(key, reader.Value.ToString());
				}
			}

			return collection;
		}
开发者ID:randacc,项目名称:ravendb,代码行数:30,代码来源:NameValueCollectionJsonConverter.cs

示例9: ReadJson

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

            var keyType = objectType.GetGenericArguments()[0];
            var keyValueType = keyType.BaseType.GetGenericArguments()[0];
            var valueType = objectType.GetGenericArguments()[1];
            var intermediateDictionaryType = typeof(Dictionary<,>).MakeGenericType(typeof(string), valueType);
            var intermediateDictionary = (IDictionary)Activator.CreateInstance(intermediateDictionaryType);
            serializer.Populate(reader, intermediateDictionary);

            var valueProperty = keyType.GetProperty("Value");
            var finalDictionary = (IDictionary)Activator.CreateInstance(objectType);
            foreach (DictionaryEntry pair in intermediateDictionary)
            {
                object value;
                if (keyValueType == typeof(Guid))
                    value = Guid.Parse(pair.Key.ToString());
                else
                    value = Convert.ChangeType(pair.Key, keyValueType, null);

                var key = Activator.CreateInstance(keyType);
                valueProperty.SetValue(key, value, null);
                finalDictionary.Add(key, pair.Value);
            }
            return finalDictionary;
        }
开发者ID:LenFon,项目名称:Bifrost,代码行数:28,代码来源:ConceptDictionaryConverter.cs

示例10: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			var s = reader.Value as string;
		    if(s != null)
			{
				if (objectType == typeof(DateTime) || objectType == typeof(DateTime?))
				{
					DateTime time;
					if (DateTime.TryParseExact(s, Default.DateTimeFormatsToRead, CultureInfo.InvariantCulture,
					                           DateTimeStyles.RoundtripKind, out time))
					{
						if (time.Kind == DateTimeKind.Unspecified)
							return DateTime.SpecifyKind(time, DateTimeKind.Local);
						if (s.EndsWith("+00:00"))
							return time.ToUniversalTime();
						return time;
					}
				}
				if(objectType == typeof(DateTimeOffset) || objectType == typeof(DateTimeOffset?))
				{
					DateTimeOffset time;
					if (DateTimeOffset.TryParseExact(s, Default.DateTimeFormatsToRead, CultureInfo.InvariantCulture,
											   DateTimeStyles.RoundtripKind, out time))
						return time;
				}

			}
			return DeferReadToNextConverter(reader, objectType, serializer, existingValue);
		}
开发者ID:shiranGinige,项目名称:ravendb,代码行数:29,代码来源:JsonDateTimeISO8601Converter.cs

示例11: Deserialize

 protected object Deserialize(JsonReader reader, Type type)
 {
     using (RavenJTokenReader tokenReader = new RavenJTokenReader(RavenJToken.ReadFrom(reader)))
     {
         return serializer.Deserialize(tokenReader, type);
     }
 }
开发者ID:etishor,项目名称:SerializationTests,代码行数:7,代码来源:RavenJsonAdapter.cs

示例12: ReadJson

 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     var s = reader.Value as string;
     if (s == null)
         return null;
     return Etag.Parse(s);
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:7,代码来源:EtagJsonConverter.cs

示例13: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            try
            {
                var jsonObject = JObject.Load(reader);
                var className = jsonObject.Property("ClassName").Value.ToString();
                var name = jsonObject.Property("Name").Value.ToString();
                var assemblyName = jsonObject.Property("AssemblyName").Value.ToString();
                var signature = jsonObject.Property("Signature").Value.ToString();

                var start = signature.IndexOf('(') + 1;
                var end = signature.IndexOf(')');
                var parametersString = signature.Substring(start, end - start);
                var parameterTypeStrings = parametersString.Split(',');

                if (string.IsNullOrEmpty(className) ||
                    string.IsNullOrEmpty(name) ||
                    string.IsNullOrEmpty(assemblyName) ||
                    parameterTypeStrings == null)
                    throw new ArgumentException("Json object is not representing a MethodInfo");

                var typeName = string.Format("{0}, {1}", className, assemblyName);
                var type = Type.GetType(typeName);
                var method = type.GetMethods().Where(m => m.Name.Equals(name) && DoesSignatureMatch(m, parameterTypeStrings)).SingleOrDefault();
                return method;
            }
            catch {
                return null;
            }
        }
开发者ID:JoB70,项目名称:Bifrost,代码行数:30,代码来源:MethodInfoConverter.cs

示例14: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			// NOTE: THIS DOESN'T SUPPORT READING OF DynamicJsonObject !!!

			var o = RavenJToken.Load(reader);
			return (o.Type == JTokenType.Null || o.Type == JTokenType.Undefined) ? null : o;
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:7,代码来源:JsonToJsonConverter.cs

示例15: DeferReadToNextConverter

		protected object DeferReadToNextConverter(JsonReader reader, Type objectType, JsonSerializer serializer, object existingValue)
		{
			var anotherConverter = serializer.Converters
				.Skip(serializer.Converters.IndexOf(this) + 1)
				.FirstOrDefault(x => x.CanConvert(objectType));
			if (anotherConverter != null)
				return anotherConverter.ReadJson(reader, objectType, existingValue, serializer);
			return reader.Value;
		}
开发者ID:royra,项目名称:ravendb,代码行数:9,代码来源:RavenJsonConverter.cs


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