當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。