-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:
JamesNK
2011-08-05 08:38:47 +00:00
parent d8b32dfdc4
commit 7d3ce867da
15 changed files with 570 additions and 8 deletions
+24
View File
@@ -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>