JavaScriptConverter.Serialize(Object, JavaScriptSerializer) Método
Definição
Quando substituído em uma classe derivada, cria um dicionário de pares nome/valor.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)
Parâmetros
- obj
- Object
O objeto a ser serializado.The object to serialize.
- serializer
- JavaScriptSerializer
O objeto que é responsável pela serialização.The object that is responsible for the serialization.
Retornos
Um objeto que contém pares chave/valor que representam os dados do objeto.An object that contains key/value pairs that represent the object's data.
Comentários
Quando você serializa um tipo para o qual um conversor personalizado é registrado, a JavaScriptSerializer instância invoca o Serialize método.When you serialize a type for which a custom converter is registered, the JavaScriptSerializer instance invokes the Serialize method.
Notas aos Implementadores
O valor de retorno de Serialize(Object, JavaScriptSerializer) deve ser uma IDictionary<TKey,TValue> instância com zero ou mais pares de nome/valor que representem os dados de um objeto a serem convertidos em JSON.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. O próprio conversor não serializa dados como JSON.The converter itself does not serialize data as JSON. Em vez disso, o conversor cria um dicionário de pares de nome/valor que contêm os nomes de propriedade (a chave de cadeia de caracteres para o dicionário) e os valores de propriedade correspondentes (o valor do objeto no dicionário).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). A JavaScriptSerializer instância, em seguida, converte esses em JSON.The JavaScriptSerializer instance subsequently converts these to JSON.
Se o conversor encontrar uma exceção, ele deverá gerar um InvalidOperationException erro que descreve o problema.If the converter encounters an exception, it should throw an InvalidOperationException error that describes the problem.