JsonSerializer.Serialize Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Sobrecargas
| Nombre | Description |
|---|---|
| Serialize(Object, JsonTypeInfo) |
Convierte el valor proporcionado en .String |
| Serialize(Stream, Object, JsonTypeInfo) |
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream |
| Serialize(Object, Type, JsonSerializerOptions) |
Convierte el valor de un tipo especificado en una cadena JSON. |
| Serialize(Object, Type, JsonSerializerContext) |
Convierte el valor proporcionado en .String |
| Serialize(Utf8JsonWriter, Object, JsonTypeInfo) |
Escribe un valor JSON (incluidos objetos o matrices) en el escritor proporcionado. |
| Serialize(Stream, Object, Type, JsonSerializerOptions) |
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream |
| Serialize(Stream, Object, Type, JsonSerializerContext) |
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream |
| Serialize(Utf8JsonWriter, Object, Type, JsonSerializerOptions) |
Escribe la representación JSON del tipo especificado en el escritor proporcionado. |
| Serialize(Utf8JsonWriter, Object, Type, JsonSerializerContext) |
Escribe un valor JSON (incluidos objetos o matrices) en el escritor proporcionado. |
| Serialize<TValue>(Utf8JsonWriter, TValue, JsonTypeInfo<TValue>) |
Escribe un valor JSON (incluidos objetos o matrices) en el escritor proporcionado. |
| Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions) |
Escribe la representación JSON de un tipo especificado por un parámetro de tipo genérico en el escritor proporcionado. |
| Serialize<TValue>(Stream, TValue, JsonTypeInfo<TValue>) |
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream |
| Serialize<TValue>(TValue, JsonSerializerOptions) |
Convierte el valor de un tipo especificado por un parámetro de tipo genérico en una cadena JSON. |
| Serialize<TValue>(TValue, JsonTypeInfo<TValue>) |
Convierte el valor proporcionado en .String |
| Serialize<TValue>(Stream, TValue, JsonSerializerOptions) |
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream |
Serialize(Object, JsonTypeInfo)
Convierte el valor proporcionado en .String
public:
static System::String ^ Serialize(System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static string Serialize(object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member Serialize : obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> string
Public Function Serialize (value As Object, jsonTypeInfo As JsonTypeInfo) As String
Parámetros
- value
- Object
Valor que se va a convertir.
- jsonTypeInfo
- JsonTypeInfo
Metadatos sobre el tipo que se va a convertir.
Devoluciones
Representación String del valor.
Excepciones
jsonTypeInfo es null.
value no coincide con el tipo de jsonTypeInfo.
Comentarios
El uso de un String elemento no es tan eficaz como el uso de codificación UTF-8, ya que la implementación usa internamente UTF-8. Consulte también SerializeToUtf8Bytes(Object, JsonTypeInfo) y SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken).
Se aplica a
Serialize(Stream, Object, JsonTypeInfo)
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream
public:
static void Serialize(System::IO::Stream ^ utf8Json, System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static void Serialize(System.IO.Stream utf8Json, object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member Serialize : System.IO.Stream * obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> unit
Public Sub Serialize (utf8Json As Stream, value As Object, jsonTypeInfo As JsonTypeInfo)
Parámetros
- value
- Object
Valor que se va a convertir.
- jsonTypeInfo
- JsonTypeInfo
Metadatos sobre el tipo que se va a convertir.
Excepciones
utf8Json es null.
value no coincide con el tipo de jsonTypeInfo.
Se aplica a
Serialize(Object, Type, JsonSerializerOptions)
Convierte el valor de un tipo especificado en una cadena JSON.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : obj * Type * System.Text.Json.JsonSerializerOptions -> string
static member Serialize : obj * Type * System.Text.Json.JsonSerializerOptions -> string
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : obj * Type * System.Text.Json.JsonSerializerOptions -> string
Public Function Serialize (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As 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.
- inputType
- Type
Tipo de que value se va a convertir.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de conversión.
Devoluciones
Representación de cadena JSON del valor.
- Atributos
Excepciones
inputType no es compatible con value.
inputType es null.
No hay compatibilidad JsonConverter para inputType ni para sus miembros serializables.
Comentarios
El uso de un String elemento no es tan eficaz como el uso de codificación UTF-8, ya que la implementación usa internamente UTF-8. Consulte también SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) y SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).
Para obtener más información, consulte Cómo serializar y deserializar JSON.
Se aplica a
Serialize(Object, Type, JsonSerializerContext)
Convierte el valor proporcionado en .String
public:
static System::String ^ Serialize(System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static string Serialize(object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member Serialize : obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> string
Public Function Serialize (value As Object, inputType As Type, context As JsonSerializerContext) As String
Parámetros
- value
- Object
Valor que se va a convertir.
- inputType
- Type
Tipo de que value se va a convertir.
- context
- JsonSerializerContext
Proveedor de metadatos para tipos serializables.
Devoluciones
Representación String del valor.
Excepciones
No hay compatibilidad JsonConverter para inputType ni para sus miembros serializables.
El GetTypeInfo(Type) método de las devoluciones proporcionadas contextnull para el tipo que se va a convertir.
inputType o context es null.
Comentarios
El uso de no String es tan eficaz como el uso de codificación UTF-8, ya que la implementación usa internamente UTF-8. SerializeToUtf8Bytes(Object, Type, JsonSerializerContext) Vea también y SerializeAsync(Stream, Object, Type, JsonSerializerContext, CancellationToken).
Se aplica a
Serialize(Utf8JsonWriter, Object, JsonTypeInfo)
Escribe un valor JSON (incluidos objetos o matrices) en el escritor proporcionado.
public:
static void Serialize(System::Text::Json::Utf8JsonWriter ^ writer, System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> unit
Public Sub Serialize (writer As Utf8JsonWriter, value As Object, jsonTypeInfo As JsonTypeInfo)
Parámetros
- writer
- Utf8JsonWriter
Escritor que se va a escribir.
- value
- Object
Valor que se va a convertir y escribir.
- jsonTypeInfo
- JsonTypeInfo
Metadatos sobre el tipo que se va a convertir.
Excepciones
writer o jsonTypeInfo es null.
value no coincide con el tipo de jsonTypeInfo.
Se aplica a
Serialize(Stream, Object, Type, JsonSerializerOptions)
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize (utf8Json As Stream, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing)
Parámetros
- value
- Object
Valor que se va a convertir.
- inputType
- Type
Tipo de que value se va a convertir.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de conversión.
- Atributos
Excepciones
inputType no es compatible con value.
utf8Json o inputType es null.
No hay compatibilidad JsonConverter para inputType ni para sus miembros serializables.
Se aplica a
Serialize(Stream, Object, Type, JsonSerializerContext)
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream
public:
static void Serialize(System::IO::Stream ^ utf8Json, System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> unit
Public Sub Serialize (utf8Json As Stream, value As Object, inputType As Type, context As JsonSerializerContext)
Parámetros
- value
- Object
Valor que se va a convertir.
- inputType
- Type
Tipo de que value se va a convertir.
- context
- JsonSerializerContext
Proveedor de metadatos para tipos serializables.
Excepciones
inputType no es compatible con value.
utf8Json, inputTypeo context es null.
No hay compatibilidad JsonConverter para inputType ni para sus miembros serializables.
Se aplica a
Serialize(Utf8JsonWriter, Object, Type, JsonSerializerOptions)
Escribe la representación JSON del tipo especificado en el escritor proporcionado.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize (writer As Utf8JsonWriter, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing)
Public Shared Sub Serialize (writer As Utf8JsonWriter, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing)
Parámetros
- writer
- Utf8JsonWriter
Escritor JSON en el que se va a escribir.
- value
- Object
Valor que se va a convertir y escribir.
- inputType
- Type
Tipo de que value se va a convertir.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de serialización.
- Atributos
Excepciones
inputType no es compatible con value
writer o inputType es null.
No hay compatibilidad JsonConverter para inputType ni para sus miembros serializables.
Comentarios
JsonWriterOptions que se usa para crear la instancia de Utf8JsonWriter tiene prioridad sobre cuando JsonSerializerOptions entran en conflicto. Por lo tanto, JsonWriterOptions.Indented, JsonWriterOptions.SkipValidationy JsonWriterOptions.Encoder se usan al escribir.
Para obtener más información, consulte Cómo serializar y deserializar JSON.
Se aplica a
Serialize(Utf8JsonWriter, Object, Type, JsonSerializerContext)
Escribe un valor JSON (incluidos objetos o matrices) en el escritor proporcionado.
public:
static void Serialize(System::Text::Json::Utf8JsonWriter ^ writer, System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> unit
Public Sub Serialize (writer As Utf8JsonWriter, value As Object, inputType As Type, context As JsonSerializerContext)
Parámetros
- writer
- Utf8JsonWriter
Escritor JSON en el que se va a escribir.
- value
- Object
Valor que se va a convertir y escribir.
- inputType
- Type
Tipo de que value se va a convertir.
- context
- JsonSerializerContext
Proveedor de metadatos para tipos serializables.
Excepciones
inputType no es compatible con value.
writer o inputType es null.
No hay compatibilidad JsonConverter para inputType ni para sus miembros serializables.
El GetTypeInfo(Type) método de las devoluciones proporcionadas contextnull para el tipo que se va a convertir.
Se aplica a
Serialize<TValue>(Utf8JsonWriter, TValue, JsonTypeInfo<TValue>)
Escribe un valor JSON (incluidos objetos o matrices) en el escritor proporcionado.
public:
generic <typename TValue>
static void Serialize(System::Text::Json::Utf8JsonWriter ^ writer, TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static void Serialize<TValue>(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> unit
Public Sub Serialize(Of TValue) (writer As Utf8JsonWriter, value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue))
Parámetros de tipo
- TValue
Tipo del valor que se va a serializar.
Parámetros
- writer
- Utf8JsonWriter
Escritor que se va a escribir.
- value
- TValue
Valor que se va a convertir y escribir.
- jsonTypeInfo
- JsonTypeInfo<TValue>
Metadatos sobre el tipo que se va a convertir.
Excepciones
writer o jsonTypeInfo es null.
No hay compatibilidad JsonConverter para TValue ni para sus miembros serializables.
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 escritor proporcionado.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize(Of TValue) (writer As Utf8JsonWriter, value As TValue, Optional options As JsonSerializerOptions = Nothing)
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.
Parámetros
- writer
- Utf8JsonWriter
Escritor JSON en el que se va a escribir.
- value
- TValue
Valor que se va a convertir y escribir.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de serialización.
- Atributos
Excepciones
writer es null.
No hay compatibilidad JsonConverter para TValue ni para sus miembros serializables.
Comentarios
JsonWriterOptions que se usa para crear la instancia de Utf8JsonWriter tiene prioridad sobre cuando JsonSerializerOptions entran en conflicto. Por lo tanto, JsonWriterOptions.Indented, JsonWriterOptions.SkipValidationy JsonWriterOptions.Encoder se usan al escribir.
Para obtener más información, consulte Cómo serializar y deserializar JSON.
Se aplica a
Serialize<TValue>(Stream, TValue, JsonTypeInfo<TValue>)
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream
public:
generic <typename TValue>
static void Serialize(System::IO::Stream ^ utf8Json, TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> unit
Public Sub Serialize(Of TValue) (utf8Json As Stream, value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue))
Parámetros de tipo
- TValue
Tipo del valor que se va a serializar.
Parámetros
- value
- TValue
Valor que se va a convertir.
- jsonTypeInfo
- JsonTypeInfo<TValue>
Metadatos sobre el tipo que se va a convertir.
Excepciones
utf8Json es null.
No hay compatibilidad JsonConverter para TValue ni para sus miembros serializables.
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.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
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);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : 'Value * System.Text.Json.JsonSerializerOptions -> string
static member Serialize : 'Value * System.Text.Json.JsonSerializerOptions -> string
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : 'Value * System.Text.Json.JsonSerializerOptions -> string
Public Function Serialize(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As 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.
Parámetros
- value
- TValue
Valor que se va a convertir.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de serialización.
Devoluciones
Representación de cadena JSON del valor.
- Atributos
Excepciones
No hay compatibilidad JsonConverter para TValue ni para sus miembros serializables.
Comentarios
El uso de un String elemento no es tan eficaz como el uso de codificación UTF-8, ya que la implementación usa internamente UTF-8. Consulte también SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) y SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).
Para obtener más información, consulte Cómo serializar y deserializar JSON.
Se aplica a
Serialize<TValue>(TValue, JsonTypeInfo<TValue>)
Convierte el valor proporcionado en .String
public:
generic <typename TValue>
static System::String ^ Serialize(TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static string Serialize<TValue>(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member Serialize : 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> string
Public Function Serialize(Of TValue) (value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue)) As String
Parámetros de tipo
- TValue
Tipo del valor que se va a serializar.
Parámetros
- value
- TValue
Valor que se va a convertir.
- jsonTypeInfo
- JsonTypeInfo<TValue>
Metadatos sobre el tipo que se va a convertir.
Devoluciones
Representación String del valor.
Excepciones
No hay compatibilidad JsonConverter para TValue ni para sus miembros serializables.
jsonTypeInfo es null.
Comentarios
El uso de un String elemento no es tan eficaz como el uso de codificación UTF-8, ya que la implementación usa internamente UTF-8. Consulte también SerializeToUtf8Bytes<TValue>(TValue, JsonTypeInfo<TValue>) y SerializeAsync<TValue>(Stream, TValue, JsonTypeInfo<TValue>, CancellationToken).
Se aplica a
Serialize<TValue>(Stream, TValue, JsonSerializerOptions)
Convierte el valor proporcionado en texto JSON codificado UTF-8 y lo escribe en .Stream
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize(Of TValue) (utf8Json As Stream, value As TValue, Optional options As JsonSerializerOptions = Nothing)
Parámetros de tipo
- TValue
Tipo del valor que se va a serializar.
Parámetros
- value
- TValue
Valor que se va a convertir.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento de conversión.
- Atributos
Excepciones
utf8Json es null.
No hay compatibilidad JsonConverter para TValue ni para sus miembros serializables.