本文整理汇总了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()))
);
}
示例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);
}
示例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();
}
示例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());
}
示例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();
}
示例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();
}
示例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());
}
示例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();
}
示例9: WriteJson
/// <inheritdoc/>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
writer.WriteNull();
else
writer.WriteValue(((TimeSpan)value).TotalMilliseconds);
}
示例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);
}
}
}
示例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();
}
示例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);
}
示例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;
}
示例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();
}
);
}
示例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();
}