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


C# JsonWriter.WriteNull方法代码示例

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


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

示例1: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var marker = value as Types;
			if (marker == null)
			{
				writer.WriteNull();
				return;
			}
			marker.Match(
				all=> writer.WriteNull(),
				many => writer.WriteValue(((IUrlParameter)marker).GetString(serializer.GetConnectionSettings()))
			);
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:13,代码来源:TypesMultiSyntaxJsonConverter.cs

示例2: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is Enum))
            {
                base.WriteJson(writer, value, serializer);
                return;
            }

            var enumType = value.GetType();
            var enumField = enumType.GetField(value.ToString());

            var attribute = enumField.GetCustomAttributes<SkyScannerEnumValueAttribute>().FirstOrDefault();
            if (attribute == null)
            {
                base.WriteJson(writer, value, serializer);
                return;
            }

            if (attribute.Value == null)
            {
                writer.WriteNull();
                return;
            }

            writer.WriteValue(attribute.Value);
        }
开发者ID:jochenvanwylick,项目名称:SkyScanner,代码行数:26,代码来源:SkyScannerStringEnumConverter.cs

示例3: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var push = value as PushNotification;
            if (push == null)
            {
                writer.WriteNull();
                return;
            }

            writer.StartObject();
            // Write push type
            if (string.IsNullOrWhiteSpace(push.Query) == false)
                writer.WriteProperty("query", push.Query);
            else if( push.Channels.Count() > 0 )
                writer.WriteArray("channels", push.Channels);
            else if( push.DeviceIds.Count() > 0 )
                writer.WriteArray("deviceids", push.DeviceIds);
            else
                writer.WriteProperty("broadcast", true);
            // Write data
            WriteData(writer, push);
            // Write platform options
            WritePlatformOptions(writer, push.PlatformOptions);
            writer.EndObject();

        }
开发者ID:neilunadkat,项目名称:appacitive-dotnet-sdk,代码行数:26,代码来源:PushNotificationConverter.cs

示例4: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value == null)
         writer.WriteNull();
     else
         writer.WriteRawValue(EpochTime.ConvertDateTimeToEpoch((DateTime)value).ToString());
 }
开发者ID:barclayadam,项目名称:stripe.net,代码行数:7,代码来源:StripeDateTimeConverter.cs

示例5: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var collection = (NameValueCollection)value;

            writer.WriteStartObject();

            foreach (var key in collection.AllKeys)
            {
                writer.WritePropertyName(key);

                var values = collection.GetValues(key);
                if (values == null)
                {
                    writer.WriteNull();
                    continue;
                }
                if (values.Length == 1)
                {
                    writer.WriteValue(values[0]);
                }
                else
                {
                    writer.WriteStartArray();

                    foreach (var item in values)
                    {
                        writer.WriteValue(item);
                    }

                    writer.WriteEndArray();
                }

            }
            writer.WriteEndObject();
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:35,代码来源:NaveValueCollectionJsonConverterOnlyForConfigFormatters.cs

示例6: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var term = value as Term;
            if (term != null)
            {
                writer.WriteStartObject();
                writer.WritePropertyName(term.Field);
                writer.WriteStartObject();

                    writer.WritePropertyName("value");
                    writer.WriteValue(term.Value);

                if (term.Boost.HasValue)
                {
                    writer.WritePropertyName("boost");
                    writer.WriteValue(term.Boost.Value);
                }
                var multiTerm = value as IMultiTermQuery;
                if (multiTerm != null)
                {
                    if (multiTerm.Rewrite.HasValue)
                    {
                        writer.WritePropertyName("rewrite");
                        writer.WriteValue(Enum.GetName(typeof(RewriteMultiTerm), multiTerm.Rewrite.Value));
                    }
                }

                writer.WriteEndObject();
                writer.WriteEndObject();
            }
            else
                writer.WriteNull();
        }
开发者ID:base31,项目名称:NEST,代码行数:33,代码来源:TermConverter.cs

示例7: WriteJson

		/// <summary>
		/// Writes the JSON representation of the object.
		/// </summary>
		/// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param>
		/// <param name="value">The value.</param>
		/// <param name="serializer">The calling serializer.</param>
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			if(value == null)
				writer.WriteNull();
			else
				writer.WriteValue(value.ToString());
		}
开发者ID:bstrausser,项目名称:ravendb,代码行数:13,代码来源:JsonEnumConverter.cs

示例8: WriteObject

        private static void WriteObject(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            Type valueType = value.GetType();
            TypeInfo valueTypeInfo = valueType.GetTypeInfo();

            writer.WriteStartObject();

            writer.WritePropertyName("$type");
            writer.WriteValue(NameUtility.GetSimpleAssemblyQualifiedName(valueType));

            writer.WritePropertyName("$value");
            
            if (valueTypeInfo.IsPrimitive)
                writer.WriteValue(value);
            else
                serializer.Serialize(writer, value);

            writer.WriteEndObject();
        }
开发者ID:Inverness,项目名称:Coroutines,代码行数:25,代码来源:NameValueDictionaryConverter.cs

示例9: WriteJson

 /// <inheritdoc/>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value == null)
         writer.WriteNull();
     else
         writer.WriteValue(((TimeSpan)value).TotalMilliseconds);
 }
开发者ID:artikh,项目名称:CouchDude,代码行数:8,代码来源:TimeSpanConverter.cs

示例10: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
   if (value == null)
   {
     writer.WriteNull();
   }
   else
   {
     Enum @enum = (Enum) value;
     string first = @enum.ToString("G");
     if (char.IsNumber(first[0]) || (int) first[0] == 45)
     {
       writer.WriteValue(value);
     }
     else
     {
       string second;
       this.GetEnumNameMap(@enum.GetType()).TryGetByFirst(first, out second);
       second = second ?? first;
       if (this.CamelCaseText)
         second = string.Join(", ", Enumerable.ToArray<string>(Enumerable.Select<string, string>((IEnumerable<string>) second.Split(new char[1]
         {
           ','
         }), (Func<string, string>) (item => StringUtils.ToCamelCase(item.Trim())))));
       writer.WriteValue(second);
     }
   }
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:28,代码来源:StringEnumConverter.cs

示例11: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            EnsureReflectionObject(value.GetType());

            DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;

            string keyName = (string)_reflectionObject.GetValue(value, KeyPropertyName);
            object keyValue = _reflectionObject.GetValue(value, ValuePropertyName);

            Type keyValueType = (keyValue != null) ? keyValue.GetType() : null;

            writer.WriteStartObject();
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(KeyPropertyName) : KeyPropertyName);
            writer.WriteValue(keyName);
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(TypePropertyName) : TypePropertyName);
            writer.WriteValue((keyValueType != null) ? keyValueType.FullName : null);

            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(ValuePropertyName) : ValuePropertyName);

            if (keyValueType != null)
            {
                string valueJson;
                if (JsonSerializerInternalWriter.TryConvertToString(keyValue, keyValueType, out valueJson))
                    writer.WriteValue(valueJson);
                else
                    writer.WriteValue(keyValue);
            }
            else
            {
                writer.WriteNull();
            }

            writer.WriteEndObject();
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:40,代码来源:EntityKeyMemberConverter.cs

示例12: ValueFormatting

		public void ValueFormatting()
		{
			StringBuilder sb = new StringBuilder();
			StringWriter sw = new StringWriter(sb);

			using (JsonWriter jsonWriter = new JsonWriter(sw))
			{
				jsonWriter.WriteStartArray();
				jsonWriter.WriteValue('@');
				jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
				jsonWriter.WriteValue(true);
				jsonWriter.WriteValue(10);
				jsonWriter.WriteValue(10.99);
				jsonWriter.WriteValue(0.99);
				jsonWriter.WriteValue(0.000000000000000001d);
				jsonWriter.WriteValue(0.000000000000000001m);
				jsonWriter.WriteValue(null);
				jsonWriter.WriteValue("This is a string.");
				jsonWriter.WriteNull();
				jsonWriter.WriteUndefined();
				jsonWriter.WriteEndArray();
			}

			string expected = @"[""@"",""\r\n\t\f\b?{\\r\\n\""'"",true,10,10.99,0.99,1E-18,0.000000000000000001,"""",""This is a string."",null,undefined]";
			string result = sb.ToString();

			Console.WriteLine("ValueFormatting");
			Console.WriteLine(result);

			Assert.AreEqual(expected, result);
		}
开发者ID:mrkurt,项目名称:mubble-old,代码行数:31,代码来源:JsonWriterTest.cs

示例13: WriteJson

        public override void WriteJson(
            JsonWriter writer,
            object value,
            JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            byte[] data = (byte[])value;

            // Compose an array.
            writer.WriteStartArray();
            Formatting oldFormatting = writer.Formatting;
            writer.Formatting = Formatting.None;

            for (var i = 0; i < data.Length; i++)
            {
                writer.WriteValue(data[i]);
            }

            writer.WriteEndArray();
            writer.Formatting = oldFormatting;
        }
开发者ID:ChrisBlueStone,项目名称:RopeSnake,代码行数:26,代码来源:ByteArrayConverter.cs

示例14: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var marker = value as Indices;
			if (marker == null)
			{
				writer.WriteNull();
				return;
			}
			marker.Match(
				all =>
				{
					writer.WriteStartArray();
					writer.WriteValue("_all");
					writer.WriteEndArray();
				},
				many =>
				{
					var settings = serializer.GetConnectionSettings();
					writer.WriteStartArray();
					foreach (var m in many.Indices.Cast<IUrlParameter>())
						writer.WriteValue(m.GetString(settings));
					writer.WriteEndArray();
				}
			);
		}
开发者ID:c1sc0,项目名称:elasticsearch-net,代码行数:25,代码来源:IndicesJsonConverter.cs

示例15: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var request = value as UpdateListItemsRequest;
            if (request == null)
            {
                writer.WriteNull();
                return;
            }
            /*
             "additems" : ["3","4","5"],
            "adduniqueitems" : ["1","6"],
            "removeitems": ["2","5"]
             */
            writer.WriteStartObject();
            writer.WritePropertyName(request.Property );
            writer.WriteStartObject();
            if (request.ItemsToAdd.Count > 0)
            {
                if (request.AddUniquely == true)
                    writer.WriteArray("adduniqueitems", request.ItemsToAdd);
                else
                    writer.WriteArray("additems", request.ItemsToAdd);
            }
            if (request.ItemsToRemove.Count > 0)
                writer.WriteArray("removeitems", request.ItemsToRemove);

            writer.WriteEndObject();
            writer.WriteEndObject();
        }
开发者ID:ytokas,项目名称:appacitive-dotnet-sdk,代码行数:29,代码来源:UpdateListItemsRequestConverter.cs


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