-Added ToObject to JToken for deserializing LINQ to JSON objects to a .NET object
-Added support for Guid, TimeSpan and Uri to LINQ to JSON
This commit is contained in:
@@ -1157,6 +1157,30 @@ namespace Newtonsoft.Json.Linq
|
||||
return FromObjectInternal(o, jsonSerializer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the specified .NET type from the <see cref="JToken"/>.
|
||||
/// </summary>
|
||||
/// <returns>The new object created from the JSON value.</returns>
|
||||
public T ToObject<T>()
|
||||
{
|
||||
return ToObject<T>(new JsonSerializer());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the specified .NET type from the <see cref="JToken"/> using the specified <see cref="JsonSerializer"/>.
|
||||
/// </summary>
|
||||
/// <param name="jsonSerializer">The <see cref="JsonSerializer"/> that will be used when creating the object.</param>
|
||||
/// <returns>The new object created from the JSON value.</returns>
|
||||
public T ToObject<T>(JsonSerializer jsonSerializer)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(jsonSerializer, "jsonSerializer");
|
||||
|
||||
using (JTokenReader jsonReader = new JTokenReader(this))
|
||||
{
|
||||
return jsonSerializer.Deserialize<T>(jsonReader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="JToken"/> from a <see cref="JsonReader"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user