Export (0) Print
Expand All

JavaScriptSerializer.ConvertToType Method (Object, Type)

Converts the specified object to the specified type.

Namespace:  System.Web.Script.Serialization
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public Object ConvertToType(
	Object obj,
	Type targetType
)

Parameters

obj
Type: System.Object

The object to convert.

targetType
Type: System.Type

The type to convert the object to.

Return Value

Type: System.Object
The serialized JSON string.

ExceptionCondition
InvalidOperationException

The resulting JSON-formatted string exceeds the value of MaxJsonLength.

-or-

obj contains a circular reference. A circular reference occurs when a child object has a reference to a parent object, and the parent object has a reference to the child object.

ArgumentException

The recursion limit defined by RecursionLimit was exceeded.

When the JavaScriptSerializer instance is serializing a type for which a custom converter is registered, the serializer calls the Serialize method to obtain the dictionary of name/value pairs that will be converted to a JSON-formatted string.

The Serialize method can also throw exceptions if the object graph is too complex, or if registered instances of JavaScriptConverter have caused converter recursion.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft