本文整理汇总了C#中Newtonsoft.Json.JsonReader.CanReadArray方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.CanReadArray方法的具体用法?C# JsonReader.CanReadArray怎么用?C# JsonReader.CanReadArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.CanReadArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
/// <summary>
/// Reads the JSON representation of an <see cref="EntityCollection{T}"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
var collection = (EntityCollection)Activator.CreateInstance(objectType);
if (reader.CanReadArray())
{
while (reader.Read() && reader.TokenType != JsonToken.EndArray)
collection.Add((Entity)StateObjectConverter.Default.ReadJson(reader, collection.EntityType, null, serializer));
}
return collection;
}
示例2: ReadJson
/// <summary>
/// Reads the JSON representation of an <see cref="EventCollection"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
return reader.CanReadArray() ? new EventCollection(serializer.Deserialize<List<Event>>(reader)) : null;
}