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


C# JsonReader.ReadAsBoolean方法代码示例

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


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

示例1: ReadIdentityInfo

        public IdentityInfo ReadIdentityInfo(JsonReader reader)
        {
            IdentityInfo info = new IdentityInfo();
            reader.Read();
            while (reader.TokenType == JsonToken.PropertyName)
            {
                switch ((string)reader.Value)
                {
                    case "toStr": info.ToStr = reader.ReadAsString(); break;
                    case "id": info.Id = reader.ReadAsString(); break;
                    case "isNew": info.IsNew = reader.ReadAsBoolean(); break;
                    case "Type": info.Type = reader.ReadAsString(); break;
                    case "ticks": info.Ticks = long.Parse(reader.ReadAsString()); break;
                    case "modified": info.Modified = bool.Parse(reader.ReadAsString()); break;
                    default: return info;
                }

                reader.Read();
            }

            if (info.Type == null)
                throw new JsonSerializationException($"Expected member 'Type' not found in {reader.Path}");

            return info;
        }
开发者ID:signumsoftware,项目名称:framework,代码行数:25,代码来源:EntityJsonConverter.cs

示例2: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			if (reader.TokenType == JsonToken.String)
			{
				return new Attachment { Content = (string)reader.Value };
			}

			if (reader.TokenType == JsonToken.StartObject)
			{
				var attachment = new Attachment();
				while (reader.Read())
				{
					if (reader.TokenType == JsonToken.PropertyName)
					{
						var propertyName = (string)reader.Value;
						switch (propertyName.ToLowerInvariant())
						{
							case "_content":
							case "content":
								attachment.Content = reader.ReadAsString();
								break;
							case "_name":
							case "name":
								attachment.Name = reader.ReadAsString();
								break;
							case "author":
								attachment.Author = reader.ReadAsString();
								break;
							case "keywords":
								attachment.Keywords = reader.ReadAsString();
								break;
							case "date":
								reader.Read();
								switch (reader.TokenType)
								{
									case JsonToken.String:
										var value = (string)reader.Value;
										if (!string.IsNullOrEmpty(value))
											attachment.Date = Convert.ToDateTime(value);
										break;
									case JsonToken.Date:
										attachment.Date = (DateTime?)reader.Value;
										break;
								}
								break;
							case "_content_type":
							case "content_type":
							case "contenttype":
							case "contentType":
								attachment.ContentType = reader.ReadAsString();
								break;
							case "_content_length":
							case "content_length":
							case "contentlength":
							case "contentLength":
								reader.Read();
								switch (reader.TokenType)
								{
									case JsonToken.String:
										var value = (string)reader.Value;
										if (!string.IsNullOrEmpty(value))
											attachment.ContentLength = Convert.ToInt64(value);
										break;
									case JsonToken.Integer:
									case JsonToken.Float:
										attachment.ContentLength = (long?)reader.Value;
										break;

								}
								break;
							case "_language":
							case "language":
								attachment.Language = reader.ReadAsString();
								break;
							case "_detect_language":
								attachment.DetectLanguage = reader.ReadAsBoolean();
								break;
							case "_indexed_chars":
							case "indexed_chars":
								reader.Read();
								switch (reader.TokenType)
								{
									case JsonToken.String:
										var value = (string)reader.Value;
										if (!string.IsNullOrEmpty(value))
											attachment.IndexedCharacters = Convert.ToInt64(value);
										break;
									case JsonToken.Integer:
									case JsonToken.Float:
										attachment.IndexedCharacters = (long?)reader.Value;
										break;

								}
								break;
							case "title":
								attachment.Title = reader.ReadAsString();
								break;
						}
					}
					if (reader.TokenType == JsonToken.EndObject)
//.........这里部分代码省略.........
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:101,代码来源:Attachment.cs


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