本文整理汇总了C#中Newtonsoft.Json.JsonWriter.WriteEndConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteEndConstructor方法的具体用法?C# JsonWriter.WriteEndConstructor怎么用?C# JsonWriter.WriteEndConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteEndConstructor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
long ticks;
if (value is DateTime)
{
DateTime dateTime = (DateTime)value;
DateTime utcDateTime = dateTime.ToUniversalTime();
ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(utcDateTime);
}
#if !NET20
else if (value is DateTimeOffset)
{
DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
DateTimeOffset utcDateTimeOffset = dateTimeOffset.ToUniversalTime();
ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(utcDateTimeOffset.UtcDateTime);
}
#endif
else
{
throw new JsonSerializationException("Expected date object value.");
}
writer.WriteStartConstructor("Date");
writer.WriteValue(ticks);
writer.WriteEndConstructor();
}
示例2: 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)
{
String isoDateTimeString;
if (value is DateTime)
{
DateTime dateTime = (DateTime)value;
if ((DateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (DateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
dateTime = dateTime.ToUniversalTime();
isoDateTimeString = dateTime.ToString(DefaultDateTimeFormat);
}
#if !PocketPC && !NET20
else if (value is DateTimeOffset)
{
DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
if ((DateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (DateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
dateTimeOffset = dateTimeOffset.ToUniversalTime();
isoDateTimeString = dateTimeOffset.ToString(DefaultDateTimeFormat);
}
#endif
else
{
throw new Exception("Expected date object value.");
}
writer.WriteStartConstructor("Date");
writer.WriteValue(isoDateTimeString);
writer.WriteEndConstructor();
}
示例3: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (!(value is DateTime))
throw new JsonSerializationException("Expected date object value.");
long num = JsonConvert.ConvertDateTimeToJavaScriptTicks(((DateTime) value).ToUniversalTime());
writer.WriteStartConstructor("Date");
writer.WriteValue(num);
writer.WriteEndConstructor();
}
示例4: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value is DateTime)
{
DateTime date = (DateTime)value;
if (date.Equals(DateTime.MinValue))
{
writer.WriteRawValue("null");
}
else
{
string template = (date.TimeOfDay == new TimeSpan(0, 0, 0)) ? "{0},{1},{2}" : "{0},{1},{2},{3},{4},{5}";
writer.WriteStartConstructor("Date");
writer.WriteRawValue(
string.Format(template, date.Year, date.Month - 1, date.Day,
date.Hour, date.Minute, date.Second));
writer.WriteEndConstructor();
}
}
}
示例5: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
string v;
if (value != null && !string.IsNullOrEmpty((v = value.ToString( ))))
{
if (System.Text.RegularExpressions.Regex.IsMatch(v, @"\[*\]"))
{
writer.WriteRawValue(v);
}
else if (System.Text.RegularExpressions.Regex.IsMatch(v, @"\{*\}"))
{
writer.WriteRawValue(v);
}
else
{
writer.WriteStartConstructor(value.ToString( ));
writer.WriteEndConstructor( );
}
}
else
writer.WriteNull( );
}
示例6: WriteTo
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WriteStartConstructor(this._name);
foreach (JToken jtoken in this.Children())
jtoken.WriteTo(writer, converters);
writer.WriteEndConstructor();
}
示例7: JsonReaderToJsonWriter
public void JsonReaderToJsonWriter(JsonReader reader, JsonWriter writer)
{
do
{
switch (reader.TokenType)
{
case JsonToken.None:
break;
case JsonToken.StartObject:
writer.WriteStartObject();
break;
case JsonToken.StartArray:
writer.WriteStartArray();
break;
case JsonToken.PropertyName:
string propertyName = reader.Value.ToString();
writer.WritePropertyName(ConvertPropertyName(propertyName));
break;
case JsonToken.Comment:
writer.WriteComment((reader.Value != null) ? reader.Value.ToString() : null);
break;
case JsonToken.Integer:
writer.WriteValue(Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
break;
case JsonToken.Float:
object value = reader.Value;
if (value is decimal)
{
writer.WriteValue((decimal)value);
}
else if (value is double)
{
writer.WriteValue((double)value);
}
else if (value is float)
{
writer.WriteValue((float)value);
}
else
{
writer.WriteValue(Convert.ToDouble(value, CultureInfo.InvariantCulture));
}
break;
case JsonToken.String:
writer.WriteValue(reader.Value.ToString());
break;
case JsonToken.Boolean:
writer.WriteValue(Convert.ToBoolean(reader.Value, CultureInfo.InvariantCulture));
break;
case JsonToken.Null:
if (this.PropertyNullValueReplaceValue != null)
{
writer.WriteValue(this.PropertyNullValueReplaceValue);
}
else
{
writer.WriteNull();
}
break;
case JsonToken.Undefined:
writer.WriteUndefined();
break;
case JsonToken.EndObject:
writer.WriteEndObject();
break;
case JsonToken.EndArray:
writer.WriteEndArray();
break;
case JsonToken.EndConstructor:
writer.WriteEndConstructor();
break;
case JsonToken.Date:
if (reader.Value is DateTimeOffset)
{
writer.WriteValue((DateTimeOffset)reader.Value);
}
else
{
writer.WriteValue(Convert.ToDateTime(reader.Value, CultureInfo.InvariantCulture));
}
break;
case JsonToken.Raw:
writer.WriteRawValue((reader.Value != null) ? reader.Value.ToString() : null);
break;
case JsonToken.Bytes:
if (reader.Value is Guid)
{
writer.WriteValue((Guid)reader.Value);
}
else
{
writer.WriteValue((byte[])reader.Value);
}
break;
}
} while (reader.Read());
}