Export (0) Print
Expand All

JavaScriptConverter.Serialize Method

When overridden in a derived class, builds a dictionary of name/value pairs.

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

public abstract IDictionary<string, Object> Serialize(
	Object obj,
	JavaScriptSerializer serializer


Type: System.Object

The object to serialize.

Type: System.Web.Script.Serialization.JavaScriptSerializer

The object that is responsible for the serialization.

Return Value

Type: System.Collections.Generic.IDictionary<String, Object>
An object that contains key/value pairs that represent the object’s data.

When you serialize a type for which a custom converter is registered, the JavaScriptSerializer instance invokes the Serialize method.

Notes to Inheritors

The return value of Serialize must be an IDictionary<TKey, TValue> instance with zero or more name/value pairs that represent an object’s data to be converted to JSON. The converter itself does not serialize data as JSON. Instead, the converter builds a dictionary of name/value pairs that contain the property names (the string key for the dictionary) and corresponding property values (the object value in the dictionary). The JavaScriptSerializer instance subsequently converts these to JSON.

If the converter encounters an exception, it should throw an InvalidOperationException error that describes the problem.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

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.

© 2014 Microsoft