Converts a given Object to a JavaScript Object Notation (JSON) string.
Syntax
CSharp
VisualBasic
ManagedCPlusPlus
JSharp
Parameters
- obj (Object)
The Object to serialize.
Return Value
Return Value
The serialized JSON string.
Remarks
When the JavaScriptSerializer instance is serializing a type for which it has a custom converter registered, the serializer calls the Serialize(Object, JavaScriptSerializer) method to obtain the dictionary of name/value pairs which 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 incorrectly caused converter recursion.
Exceptions
| Exception | Condition |
|---|
| 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. |
Assembly: System.Web.Extensions (Module: System.Web.Extensions)