Uređivanje

Dijeli putem


JavaScriptConverter.Serialize(Object, JavaScriptSerializer) Method

Definition

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

public:
 abstract System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ Serialize(System::Object ^ obj, System::Web::Script::Serialization::JavaScriptSerializer ^ serializer);
public abstract System.Collections.Generic.IDictionary<string,object> Serialize (object obj, System.Web.Script.Serialization.JavaScriptSerializer serializer);
abstract member Serialize : obj * System.Web.Script.Serialization.JavaScriptSerializer -> System.Collections.Generic.IDictionary<string, obj>
Public MustOverride Function Serialize (obj As Object, serializer As JavaScriptSerializer) As IDictionary(Of String, Object)

Parameters

obj
Object

The object to serialize.

serializer
JavaScriptSerializer

The object that is responsible for the serialization.

Returns

An object that contains key/value pairs that represent the object's data.

Remarks

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

Notes to Implementers

The return value of Serialize(Object, JavaScriptSerializer) 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.

Applies to