JsonSerializer.Serialize Método
Definición
Sobrecargas
| Serialize(Object, Type, JsonSerializerOptions) |
Convierte el valor de un tipo especificado en una cadena JSON.Converts the value of a specified type into a JSON string. |
| Serialize(Utf8JsonWriter, Object, Type, JsonSerializerOptions) |
Escribe la representación JSON del tipo especificado en el sistema de escritura proporcionado.Writes the JSON representation of the specified type to the provided writer. |
| Serialize<TValue>(TValue, JsonSerializerOptions) |
Convierte el valor de un tipo especificado por un parámetro de tipo genérico en una cadena JSON.Converts the value of a type specified by a generic type parameter into a JSON string. |
| Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions) |
Escribe la representación JSON de un tipo especificado por un parámetro de tipo genérico en el sistema de escritura proporcionado.Writes the JSON representation of a type specified by a generic type parameter to the provided writer. |
Serialize(Object, Type, JsonSerializerOptions)
Convierte el valor de un tipo especificado en una cadena JSON.Converts the value of a specified type into a JSON string.
public static string Serialize (object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static string Serialize (object value, Type inputType, System.Text.Json.JsonSerializerOptions options = default);
static member Serialize : obj * Type * System.Text.Json.JsonSerializerOptions -> string
Public Shared Function Serialize (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As String
Parámetros
- value
- Object
Valor que se va a convertir.The value to convert.
- inputType
- Type
Tipo de value que se va a convertir.The type of the value to convert.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de la conversión.Options to control the conversion behavior.
Devoluciones
Representación de cadena JSON del valor.The JSON string representation of the value.
Excepciones
inputType no es compatible con value.inputType is not compatible with value.
inputType es null.inputType is null.
No hay ningún JsonConverter compatible para inputType o sus miembros serializables.There is no compatible JsonConverter for inputType or its serializable members.
Comentarios
El uso de String no es tan eficaz como el uso de la codificación UTF-8, ya que la implementación utiliza internamente UTF-8.Using a String is not as efficient as using UTF-8 encoding since the implementation internally uses UTF-8. Vea también SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) y SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).See also SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) and SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).
Para obtener más información, vea Cómo serializar y deserializar JSON.For more information, see How to serialize and deserialize JSON.
Se aplica a
Serialize(Utf8JsonWriter, Object, Type, JsonSerializerOptions)
Escribe la representación JSON del tipo especificado en el sistema de escritura proporcionado.Writes the JSON representation of the specified type to the provided writer.
public static void Serialize (System.Text.Json.Utf8JsonWriter writer, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize (System.Text.Json.Utf8JsonWriter writer, object value, Type inputType, System.Text.Json.JsonSerializerOptions options = default);
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
Public Shared Sub Serialize (writer As Utf8JsonWriter, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing)
Parámetros
- writer
- Utf8JsonWriter
Sistema de escritura JSON en el que se va a escribir.The JSON writer to write to.
- value
- Object
Valor que se va a convertir y leer.The value to convert and write.
- inputType
- Type
Tipo de value que se va a convertir.The type of the value to convert.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de la serialización.Options to control serialization behavior.
Excepciones
inputType no es compatible con value.inputType is not compatible with value
writer o inputType es null.writer or inputType is null.
No hay ningún JsonConverter compatible para inputType o sus miembros serializables.There is no compatible JsonConverter for inputType or its serializable members.
Comentarios
JsonWriterOptionsQue se usa para crear la instancia de Utf8JsonWriter tiene prioridad sobre el JsonSerializerOptions cuando entran en conflicto.The JsonWriterOptions used to create the instance of the Utf8JsonWriter take precedence over the JsonSerializerOptions when they conflict. Por lo tanto,, JsonWriterOptions.Indented JsonWriterOptions.SkipValidation y JsonWriterOptions.Encoder se usan durante la escritura.Hence, JsonWriterOptions.Indented, JsonWriterOptions.SkipValidation, and JsonWriterOptions.Encoder are used while writing.
Para obtener más información, vea Cómo serializar y deserializar JSON.For more information, see How to serialize and deserialize JSON.
Se aplica a
Serialize<TValue>(TValue, JsonSerializerOptions)
Convierte el valor de un tipo especificado por un parámetro de tipo genérico en una cadena JSON.Converts the value of a type specified by a generic type parameter into a JSON string.
public static string Serialize<TValue> (TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static string Serialize<TValue> (TValue value, System.Text.Json.JsonSerializerOptions options = default);
static member Serialize : 'Value * System.Text.Json.JsonSerializerOptions -> string
Public Shared Function Serialize(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As String
Parámetros de tipo
- TValue
Tipo del valor que se va a serializar.The type of the value to serialize.
Parámetros
- value
- TValue
Valor que se va a convertir.The value to convert.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de la serialización.Options to control serialization behavior.
Devoluciones
Una representación de cadena JSON del valor.A JSON string representation of the value.
Excepciones
No hay ningún JsonConverter compatible para TValue o sus miembros serializables.There is no compatible JsonConverter for TValue or its serializable members.
Comentarios
El uso de String no es tan eficaz como el uso de la codificación UTF-8, ya que la implementación utiliza internamente UTF-8.Using a String is not as efficient as using UTF-8 encoding since the implementation internally uses UTF-8. Vea también SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) y SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).See also SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) and SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).
Para obtener más información, vea Cómo serializar y deserializar JSON.For more information, see How to serialize and deserialize JSON.
Se aplica a
Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)
Escribe la representación JSON de un tipo especificado por un parámetro de tipo genérico en el sistema de escritura proporcionado.Writes the JSON representation of a type specified by a generic type parameter to the provided writer.
public static void Serialize<TValue> (System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize<TValue> (System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions options = default);
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.JsonSerializerOptions -> unit
Public Shared Sub Serialize(Of TValue) (writer As Utf8JsonWriter, value As TValue, Optional options As JsonSerializerOptions = Nothing)
Parámetros de tipo
- TValue
Tipo del valor que se va a serializar.The type of the value to serialize.
Parámetros
- writer
- Utf8JsonWriter
Un sistema de escritura JSON en el que se va a escribir.A JSON writer to write to.
- value
- TValue
Valor que se va a convertir y leer.The value to convert and write.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de la serialización.Options to control serialization behavior.
Excepciones
writer es null.writer is null.
No hay ningún JsonConverter compatible para TValue o sus miembros serializables.There is no compatible JsonConverter for TValue or its serializable members.
Comentarios
JsonWriterOptionsQue se usa para crear la instancia de Utf8JsonWriter tiene prioridad sobre el JsonSerializerOptions cuando entran en conflicto.The JsonWriterOptions used to create the instance of the Utf8JsonWriter take precedence over the JsonSerializerOptions when they conflict. Por lo tanto,, JsonWriterOptions.Indented JsonWriterOptions.SkipValidation y JsonWriterOptions.Encoder se usan durante la escritura.Hence, JsonWriterOptions.Indented, JsonWriterOptions.SkipValidation, and JsonWriterOptions.Encoder are used while writing.
Para obtener más información, vea Cómo serializar y deserializar JSON.For more information, see How to serialize and deserialize JSON.