Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

JavaScriptSerializer.Serialize Method (Object)

Converts an object to a JSON string.

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

public string Serialize(
	Object obj
)

Parameters

obj
Type: System.Object

The object to serialize.

Return Value

Type: System.String
The serialized JSON string.

ExceptionCondition
InvalidOperationException

The resulting JSON 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 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.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5

Community Additions

ADD
Show:
© 2015 Microsoft