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


C# JsonSerializer.Deserialize方法代码示例

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


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

示例1: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken value = null;
            var response = new FindConnectedObjectsResponse();
            // status
            var json = JObject.ReadFrom(reader) as JObject;
            json.TryGetValue("status", out value);
            response.Status = serializer.Deserialize<Status>(value.CreateReader());
            if (response.Status.IsSuccessful == false)
                return response;
            json.Remove("status");

            // paging info
            // Extract paging info
            json.TryGetValue("paginginfo", out value);
            response.PagingInfo = serializer.Deserialize<PagingInfo>(value.CreateReader());
            json.Remove("paginginfo");

            // extract parent label
            json.TryGetValue("parent", out value);
            var parentLabel = value.ToString();

            // Extract graph node.
            json.TryGetValue("nodes", out value);
            if (value.Type != JTokenType.Null)
            {
                var nodes = value.Values<JObject>();
                ParseNodes(response, parentLabel, nodes, serializer);
            }
            else
                response.Nodes = new List<GraphNode>();
            return response;
        }
开发者ID:ytokas,项目名称:appacitive-dotnet-sdk,代码行数:33,代码来源:FindConnectedObjectsResponseConverter.cs

示例2: GetTypeFromJObject

		private IElasticCoreType GetTypeFromJObject(JObject po, JsonSerializer serializer)
		{
			JToken typeToken;
			serializer.TypeNameHandling = TypeNameHandling.None;
			if (po.TryGetValue("type", out typeToken))
			{
				var type = typeToken.Value<string>().ToLowerInvariant();
				switch (type)
				{
					case "string":
						return serializer.Deserialize(po.CreateReader(), typeof(StringMapping)) as StringMapping;
					case "float":
					case "double":
					case "byte":
					case "short":
					case "integer":
					case "long":
						return serializer.Deserialize(po.CreateReader(), typeof(NumberMapping)) as NumberMapping;
					case "date":
						return serializer.Deserialize(po.CreateReader(), typeof(DateMapping)) as DateMapping;
					case "boolean":
						return serializer.Deserialize(po.CreateReader(), typeof(BooleanMapping)) as BooleanMapping;
					case "binary":
						return serializer.Deserialize(po.CreateReader(), typeof(BinaryMapping)) as BinaryMapping;
				}
			}
			return null;
		}
开发者ID:BiYiTuan,项目名称:elasticsearch-net,代码行数:28,代码来源:ElasticCoreTypeConverter.cs

示例3: Copy

		public override void Copy(ODataObject source, JsonSerializer serializer)
		{
			if(source == null || serializer == null) return;
			base.Copy(source, serializer);

			var typedSource = source as DiskSpace;
			if(typedSource != null)
			{
				Max = typedSource.Max;
				Used = typedSource.Used;
				Free = typedSource.Free;
			}
			else
			{
				JToken token;
				if(source.TryGetProperty("Max", out token) && token.Type != JTokenType.Null)
				{
					Max = (int?)serializer.Deserialize(token.CreateReader(), typeof(int?));
				}
				if(source.TryGetProperty("Used", out token) && token.Type != JTokenType.Null)
				{
					Used = (int?)serializer.Deserialize(token.CreateReader(), typeof(int?));
				}
				if(source.TryGetProperty("Free", out token) && token.Type != JTokenType.Null)
				{
					Free = (int?)serializer.Deserialize(token.CreateReader(), typeof(int?));
				}
			}
		}
开发者ID:wholroyd,项目名称:ShareFile-NET,代码行数:29,代码来源:DiskSpace.cs

示例4: Copy

        public override void Copy(ODataObject source, JsonSerializer serializer)
        {
            if(source == null || serializer == null) return;
            base.Copy(source, serializer);

            var typedSource = source as Metadata;
            if(typedSource != null)
            {
                Name = typedSource.Name;
                Value = typedSource.Value;
                IsPublic = typedSource.IsPublic;
            }
            else
            {
                JToken token;
                if(source.TryGetProperty("Name", out token) && token.Type != JTokenType.Null)
                {
                    Name = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
                }
                if(source.TryGetProperty("Value", out token) && token.Type != JTokenType.Null)
                {
                    Value = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
                }
                if(source.TryGetProperty("IsPublic", out token) && token.Type != JTokenType.Null)
                {
                    IsPublic = (bool?)serializer.Deserialize(token.CreateReader(), typeof(bool?));
                }
            }
        }
开发者ID:BobDankert,项目名称:ShareFile-NET,代码行数:29,代码来源:Metadata.cs

示例5: Copy

        public override void Copy(ODataObject source, JsonSerializer serializer)
        {
            if(source == null || serializer == null) return;
            base.Copy(source, serializer);

            var typedSource = source as DownloadSpecification;
            if(typedSource != null)
            {
                DownloadToken = typedSource.DownloadToken;
                PrepareXmlInfo = typedSource.PrepareXmlInfo;
                DownloadUrl = typedSource.DownloadUrl;
                DownloadPrepStartURL = typedSource.DownloadPrepStartURL;
            }
            else
            {
                JToken token;
                if(source.TryGetProperty("DownloadToken", out token) && token.Type != JTokenType.Null)
                {
                    DownloadToken = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
                }
                if(source.TryGetProperty("PrepareXmlInfo", out token) && token.Type != JTokenType.Null)
                {
                    PrepareXmlInfo = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
                }
                if(source.TryGetProperty("DownloadUrl", out token) && token.Type != JTokenType.Null)
                {
                    DownloadUrl = (Uri)serializer.Deserialize(token.CreateReader(), typeof(Uri));
                }
                if(source.TryGetProperty("DownloadPrepStartURL", out token) && token.Type != JTokenType.Null)
                {
                    DownloadPrepStartURL = (Uri)serializer.Deserialize(token.CreateReader(), typeof(Uri));
                }
            }
        }
开发者ID:BobDankert,项目名称:ShareFile-NET,代码行数:34,代码来源:DownloadSpecification.cs

示例6: Copy

		public override void Copy(ODataObject source, JsonSerializer serializer)
		{
			if(source == null || serializer == null) return;
			base.Copy(source, serializer);

			var typedSource = source as Principal;
			if(typedSource != null)
			{
				Name = typedSource.Name;
				Email = typedSource.Email;
				Username = typedSource.Username;
				Domain = typedSource.Domain;
			}
			else
			{
				JToken token;
				if(source.TryGetProperty("Name", out token) && token.Type != JTokenType.Null)
				{
					Name = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("Email", out token) && token.Type != JTokenType.Null)
				{
					Email = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("Username", out token) && token.Type != JTokenType.Null)
				{
					Username = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("Domain", out token) && token.Type != JTokenType.Null)
				{
					Domain = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
			}
		}
开发者ID:wholroyd,项目名称:ShareFile-NET,代码行数:34,代码来源:Principal.cs

示例7: Copy

        public override void Copy(ODataObject source, JsonSerializer serializer)
        {
            if(source == null || serializer == null) return;
            base.Copy(source, serializer);

            var typedSource = source as FileLock;
            if(typedSource != null)
            {
                LockId = typedSource.LockId;
                LockType = typedSource.LockType;
                Owner = typedSource.Owner;
                ExpirationTimeInMinutes = typedSource.ExpirationTimeInMinutes;
            }
            else
            {
                JToken token;
                if(source.TryGetProperty("LockId", out token) && token.Type != JTokenType.Null)
                {
                    LockId = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
                }
                if(source.TryGetProperty("LockType", out token) && token.Type != JTokenType.Null)
                {
                    LockType = (SafeEnum<LockType>)serializer.Deserialize(token.CreateReader(), typeof(SafeEnum<LockType>));
                }
                if(source.TryGetProperty("Owner", out token) && token.Type != JTokenType.Null)
                {
                    Owner = (Principal)serializer.Deserialize(token.CreateReader(), typeof(Principal));
                }
                if(source.TryGetProperty("ExpirationTimeInMinutes", out token) && token.Type != JTokenType.Null)
                {
                    ExpirationTimeInMinutes = (int?)serializer.Deserialize(token.CreateReader(), typeof(int?));
                }
            }
        }
开发者ID:BobDankert,项目名称:ShareFile-NET,代码行数:34,代码来源:FileLock.cs

示例8: ReadJson

        /// <summary>
        /// Reads the JSON representation of an <see cref="EventVersion"/> instance.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">The type of object.</param>
        /// <param name="existingValue">The existing value of the object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            if (!reader.CanReadObject())
                return null;

            var item = 0;
            var count = 0;
            var version = 0;
            while (reader.Read() && reader.TokenType != JsonToken.EndObject)
            {
                String propertyName;
                if (!reader.TryGetProperty(out propertyName))
                    continue;

                switch (propertyName)
                {
                    case "v":
                        version = serializer.Deserialize<Int32>(reader);
                        break;
                    case "c":
                        count = serializer.Deserialize<Int32>(reader);
                        break;
                    case "i":
                        item = serializer.Deserialize<Int32>(reader);
                        break;
                }
            }

            return new EventVersion(version, count, item);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:37,代码来源:EventVersionConverter.cs

示例9: Copy

		public override void Copy(ODataObject source, JsonSerializer serializer)
		{
			if(source == null || serializer == null) return;
			base.Copy(source, serializer);

			var typedSource = source as DeviceUserWipe;
			if(typedSource != null)
			{
				WipeToken = typedSource.WipeToken;
				Success = typedSource.Success;
				ErrorMessage = typedSource.ErrorMessage;
			}
			else
			{
				JToken token;
				if(source.TryGetProperty("WipeToken", out token) && token.Type != JTokenType.Null)
				{
					WipeToken = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("Success", out token) && token.Type != JTokenType.Null)
				{
					Success = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("ErrorMessage", out token) && token.Type != JTokenType.Null)
				{
					ErrorMessage = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
			}
		}
开发者ID:wholroyd,项目名称:ShareFile-NET,代码行数:29,代码来源:DeviceUserWipe.cs

示例10: Copy

        public override void Copy(ODataObject source, JsonSerializer serializer)
        {
            if(source == null || serializer == null) return;
            base.Copy(source, serializer);

            var typedSource = source as FindSubdomainParams;
            if(typedSource != null)
            {
                UsernameShort = typedSource.UsernameShort;
                Password = typedSource.Password;
                EmployeeOnly = typedSource.EmployeeOnly;
            }
            else
            {
                JToken token;
                if(source.TryGetProperty("UsernameShort", out token) && token.Type != JTokenType.Null)
                {
                    UsernameShort = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
                }
                if(source.TryGetProperty("Password", out token) && token.Type != JTokenType.Null)
                {
                    Password = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
                }
                if(source.TryGetProperty("EmployeeOnly", out token) && token.Type != JTokenType.Null)
                {
                    EmployeeOnly = (bool)serializer.Deserialize(token.CreateReader(), typeof(bool));
                }
            }
        }
开发者ID:BobDankert,项目名称:ShareFile-NET,代码行数:29,代码来源:FindSubdomainParams.cs

示例11: ReadJson

        /// <summary>
        /// Reads the JSON representation of an <see cref="StateObject"/> instance.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">The type of object.</param>
        /// <param name="existingValue">The existing value of the object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            if (!reader.CanReadObject())
                return null;

            var stateObject = default(StateObject);
            var state = new Dictionary<String, Object>();
            while (reader.Read() && reader.TokenType != JsonToken.EndObject)
            {
                var propertyName = String.Empty;
                if (!reader.TryGetProperty(out propertyName))
                    continue;

                if (propertyName == TypePropertyName)
                {
                    objectType = Type.GetType(serializer.Deserialize<String>(reader), throwOnError: true, ignoreCase: true);
                    stateObject = (StateObject)FormatterServices.GetUninitializedObject(objectType);
                }
                else
                {
                    stateObject = stateObject ?? (StateObject)FormatterServices.GetUninitializedObject(objectType);
                    state.Add(propertyName, serializer.Deserialize(reader, stateObject.GetFieldType(propertyName)));
                }
            }

            stateObject?.SetState(state);

            return stateObject;
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:36,代码来源:StateObjectConverter.cs

示例12: ReadJson

        /// <summary>
        /// Reads the JSON representation of an <see cref="EventEnvelope"/> instance.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">The type of object.</param>
        /// <param name="existingValue">The existing value of the object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            if (!reader.CanReadObject())
                return null;

            var e = default(Event);
            var aggregateId = Guid.Empty;
            var correlationId = Guid.Empty;
            var version = EventVersion.Empty;
            while (reader.Read() && reader.TokenType != JsonToken.EndObject)
            {
                String propertyName;
                if (!reader.TryGetProperty(out propertyName))
                    continue;

                switch (propertyName)
                {
                    case "a":
                        aggregateId = serializer.Deserialize<Guid>(reader);
                        break;
                    case "v":
                        version = serializer.Deserialize<EventVersion>(reader);
                        break;
                    case "e":
                        e = serializer.Deserialize<Event>(reader);
                        break;
                    case "c":
                        correlationId = serializer.Deserialize<Guid>(reader);
                        break;
                }
            }

            return new EventEnvelope(correlationId, aggregateId, version, e);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:41,代码来源:EventEnvelopeConverter.cs

示例13: Copy

        public override void Copy(ODataObject source, JsonSerializer serializer)
        {
            if(source == null || serializer == null) return;
            base.Copy(source, serializer);

            var typedSource = source as MarketAnalytics;
            if(typedSource != null)
            {
                ConversionIndex = typedSource.ConversionIndex;
                ConversionIndex2 = typedSource.ConversionIndex2;
                LtvIndex = typedSource.LtvIndex;
                PlanValue = typedSource.PlanValue;
            }
            else
            {
                JToken token;
                if(source.TryGetProperty("ConversionIndex", out token) && token.Type != JTokenType.Null)
                {
                    ConversionIndex = (decimal?)serializer.Deserialize(token.CreateReader(), typeof(decimal?));
                }
                if(source.TryGetProperty("ConversionIndex2", out token) && token.Type != JTokenType.Null)
                {
                    ConversionIndex2 = (decimal?)serializer.Deserialize(token.CreateReader(), typeof(decimal?));
                }
                if(source.TryGetProperty("LtvIndex", out token) && token.Type != JTokenType.Null)
                {
                    LtvIndex = (decimal?)serializer.Deserialize(token.CreateReader(), typeof(decimal?));
                }
                if(source.TryGetProperty("PlanValue", out token) && token.Type != JTokenType.Null)
                {
                    PlanValue = (decimal?)serializer.Deserialize(token.CreateReader(), typeof(decimal?));
                }
            }
        }
开发者ID:BobDankert,项目名称:ShareFile-NET,代码行数:34,代码来源:MarketAnalytics.cs

示例14: Copy

		public override void Copy(ODataObject source, JsonSerializer serializer)
		{
			if(source == null || serializer == null) return;
			base.Copy(source, serializer);

			var typedSource = source as AccessControlFailedEntry;
			if(typedSource != null)
			{
				AccessControl = typedSource.AccessControl;
				Code = typedSource.Code;
				Message = typedSource.Message;
			}
			else
			{
				JToken token;
				if(source.TryGetProperty("AccessControl", out token) && token.Type != JTokenType.Null)
				{
					AccessControl = (AccessControl)serializer.Deserialize(token.CreateReader(), typeof(AccessControl));
				}
				if(source.TryGetProperty("Code", out token) && token.Type != JTokenType.Null)
				{
					Code = (SafeEnum<HttpStatusCode>)serializer.Deserialize(token.CreateReader(), typeof(SafeEnum<HttpStatusCode>));
				}
				if(source.TryGetProperty("Message", out token) && token.Type != JTokenType.Null)
				{
					Message = (ODataExceptionMessage)serializer.Deserialize(token.CreateReader(), typeof(ODataExceptionMessage));
				}
			}
		}
开发者ID:wholroyd,项目名称:ShareFile-NET,代码行数:29,代码来源:AccessControlFailedEntry.cs

示例15: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.ValueType == typeof(bool))
            {
                bool sourceEnabled = (bool)reader.Value;
                if (!sourceEnabled)
                    return new SourceFilter();
                else
                    return null;
            }
            else if (reader.ValueType == typeof(string))
            {
                return new SourceFilter(reader.Value.ToString());
            }
            else if (reader.TokenType == JsonToken.StartArray)
            {
                return new SourceFilter(serializer.Deserialize<IEnumerable<string>>(reader));
            }

            Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            if (fieldDict.ContainsKey(SearchPieceTypeEnum.SourceFilter.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            return new SourceFilter(
                JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_INCLUDE)),
                JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_EXCLUDE)));            
        }
开发者ID:kbolay,项目名称:Bolay.Elastic,代码行数:27,代码来源:SourceFilterSerializer.cs


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