JavaScriptConverter Class
Provides an abstract base class for a custom type converter.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
The JavaScriptConverter type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | SupportedTypes | When overridden in a derived class, gets a collection of the supported types. |
| Name | Description | |
|---|---|---|
![]() | Deserialize | When overridden in a derived class, converts the provided dictionary into an object of the specified type. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | Serialize | When overridden in a derived class, builds a dictionary of name/value pairs. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The JavaScriptConverter class enables you to implement serialization and deserialization processes for managed types that are not natively supported by the JavaScriptSerializer class. You can also use JavaScriptConverter when you need more control over the serialization and deserialization process.
The SupportedTypes property indicates the types for which a custom converter provides converter services.
To indicate that a custom converter must be used by the JavaScriptSerializer instance, you must register the converter with the instance. If you are using the JavaScriptSerializer class directly, you should use the RegisterConverters method to register the converter. Otherwise, if you are invoking Web methods from ECMAScript (JavaScript) and you want to use the custom converter, you can register it by adding a converters element in the configuration file. For more information, see How to: Configure ASP.NET Services in Microsoft Ajax.
When the JavaScriptSerializer instance is serializing a type for which it has a custom converter registered, the serializer calls the Serialize method. Similarly, when the JavaScriptSerializer instance is deserializing a JavaScript Object Notation (JSON) string and recognizes that a type inside the JSON string has a custom converter associated with it, the serializer calls the Deserialize method.
Notes to InheritorsWhen you inherit from JavaScriptConverter, you must override the following members:
JavaScriptSerializer provides the ConvertToType method that will be used by implementers of JavaScriptConverter. Converter code must be able to take a value that is contained in the dictionary that the serializer passes to it, and then convert that value into an object of type T. Rather than re-implementing the custom conversion code to accomplish this, you can call the ConvertToType method.
The following example shows how to create a custom converter for the ListItemCollection class.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.


