JsonSerializer.Deserialize Método
Definición
Sobrecargas
| Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerOptions) |
Analiza el texto con codificación UTF-8 que representa un único valor JSON en una instancia de un tipo especificado.Parses the UTF-8 encoded text representing a single JSON value into an instance of a specified type. |
| Deserialize(String, Type, JsonSerializerOptions) |
Analiza el texto que representa un único valor JSON en una instancia de un tipo especificado.Parses the text representing a single JSON value into an instance of a specified type. |
| Deserialize(Utf8JsonReader, Type, JsonSerializerOptions) |
Lee un valor JSON (incluidos objetos o matrices) desde el lector proporcionado y lo convierte en una instancia del tipo especificado.Reads one JSON value (including objects or arrays) from the provided reader and converts it into an instance of a specified type. |
| Deserialize<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions) |
Analiza el texto con codificación UTF-8 que representa un único valor JSON en una instancia del tipo especificado por un parámetro de tipo genérico.Parses the UTF-8 encoded text representing a single JSON value into an instance of the type specified by a generic type parameter. |
| Deserialize<TValue>(String, JsonSerializerOptions) |
Analiza el texto que representa un único valor JSON en una instancia del tipo especificado por un parámetro de tipo genérico.Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter. |
| Deserialize<TValue>(Utf8JsonReader, JsonSerializerOptions) |
Lee un valor JSON (incluidos objetos o matrices) desde el lector proporcionado en una instancia del tipo especificado por un parámetro de tipo genérico.Reads one JSON value (including objects or arrays) from the provided reader into an instance of the type specified by a generic type parameter. |
Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerOptions)
Analiza el texto con codificación UTF-8 que representa un único valor JSON en una instancia de un tipo especificado.Parses the UTF-8 encoded text representing a single JSON value into an instance of a specified type.
public static object? Deserialize (ReadOnlySpan<byte> utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);
public static object Deserialize (ReadOnlySpan<byte> utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions options = default);
static member Deserialize : ReadOnlySpan<byte> * Type * System.Text.Json.JsonSerializerOptions -> obj
Public Shared Function Deserialize (utf8Json As ReadOnlySpan(Of Byte), returnType As Type, Optional options As JsonSerializerOptions = Nothing) As Object
Parámetros
- utf8Json
- ReadOnlySpan<Byte>
Texto JSON que se va a analizar.The JSON text to parse.
- returnType
- Type
Tipo del objeto al que se va a convertir y devolver.The type of the object to convert to and return.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento durante el análisis.Options to control the behavior during parsing.
Devoluciones
Representación returnType del valor JSON.A returnType representation of the JSON value.
Excepciones
returnType es null.returnType is null.
El JSON no es válido.The JSON is invalid.
o bien-or-
returnType no es compatible con el JSON.returnType is not compatible with the JSON.
o bien-or-
Hay datos restantes en el intervalo más allá de un único valor JSON.There is remaining data in the span beyond a single JSON value.
No hay ningún JsonConverter compatible para returnType o sus miembros serializables.There is no compatible JsonConverter for returnType or its serializable members.
Comentarios
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
Deserialize(String, Type, JsonSerializerOptions)
Analiza el texto que representa un único valor JSON en una instancia de un tipo especificado.Parses the text representing a single JSON value into an instance of a specified type.
public static object? Deserialize (string json, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);
public static object Deserialize (string json, Type returnType, System.Text.Json.JsonSerializerOptions options = default);
static member Deserialize : string * Type * System.Text.Json.JsonSerializerOptions -> obj
Public Shared Function Deserialize (json As String, returnType As Type, Optional options As JsonSerializerOptions = Nothing) As Object
Parámetros
- json
- String
Texto JSON que se va a analizar.The JSON text to parse.
- returnType
- Type
Tipo del objeto al que se va a convertir y devolver.The type of the object to convert to and return.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento durante el análisis.Options to control the behavior during parsing.
Devoluciones
Representación returnType del valor JSON.A returnType representation of the JSON value.
Excepciones
json o returnType es null.json or returnType is null.
El JSON no es válido.The JSON is invalid.
o bien-or-
TValue no es compatible con el JSON.TValue is not compatible with the JSON.
o bien-or-
Hay datos restantes en el intervalo más allá de un único valor JSON.There is remaining data in the string beyond a single JSON value.
No hay ningún JsonConverter compatible para returnType o sus miembros serializables.There is no compatible JsonConverter for returnType or its serializable members.
Comentarios
El uso de String no es tan eficaz como el uso de los métodos UTF-8, ya que la implementación de utiliza de forma nativa UTF-8.Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
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
Deserialize(Utf8JsonReader, Type, JsonSerializerOptions)
Lee un valor JSON (incluidos objetos o matrices) desde el lector proporcionado y lo convierte en una instancia del tipo especificado.Reads one JSON value (including objects or arrays) from the provided reader and converts it into an instance of a specified type.
public static object? Deserialize (ref System.Text.Json.Utf8JsonReader? reader, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);
public static object Deserialize (ref System.Text.Json.Utf8JsonReader reader, Type returnType, System.Text.Json.JsonSerializerOptions options = default);
static member Deserialize : Utf8JsonReader * Type * System.Text.Json.JsonSerializerOptions -> obj
Public Shared Function Deserialize (ByRef reader As Utf8JsonReader, returnType As Type, Optional options As JsonSerializerOptions = Nothing) As Object
Parámetros
- reader
- Utf8JsonReader
Lector desde el que se va a leer el JSON.The reader to read the JSON from.
- returnType
- Type
Tipo del objeto al que se va a convertir y devolver.The type of the object to convert to and return.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento del serializador durante la lectura.Options to control the serializer behavior during reading.
Devoluciones
Representación returnType del valor JSON.A returnType representation of the JSON value.
Excepciones
returnType es null.returnType is null.
El JSON no es válido.The JSON is invalid.
o bien-or-
returnType no es compatible con el JSON.returnType is not compatible with the JSON.
o bien-or-
No se pudo leer un valor del lector.A value could not be read from the reader.
reader usa opciones no compatibles.reader is using unsupported options.
No hay ningún JsonConverter compatible para returnType o sus miembros serializables.There is no compatible JsonConverter for returnType or its serializable members.
Comentarios
Si la TokenType propiedad de reader es JsonTokenType.PropertyName o JsonTokenType.None , el lector estará avanzado mediante una llamada a Utf8JsonReader.Read() para determinar el inicio del valor.If the TokenType property of reader is JsonTokenType.PropertyName or JsonTokenType.None, the reader will be advanced by one call to Utf8JsonReader.Read() to determine the start of the value.
Tras completar este método, se reader colocará en el token final del valor JSON.Upon completion of this method, reader will be positioned at the final token in the JSON value. Si se produce una excepción, el lector se restablece al estado en que se encontraba cuando se llamó al método.If an exception is thrown, the reader is reset to the state it was in when the method was called.
Este método realiza una copia de los datos en los que se actuó el lector, por lo que no hay ningún requisito del llamador para mantener la integridad de los datos más allá de la devolución de este método.This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
JsonReaderOptionsQue se usa para crear la instancia de Utf8JsonReader tiene prioridad sobre el JsonSerializerOptions cuando entran en conflicto.The JsonReaderOptions used to create the instance of the Utf8JsonReader take precedence over the JsonSerializerOptions when they conflict. Por lo tanto,, JsonReaderOptions.AllowTrailingCommas JsonReaderOptions.MaxDepth y JsonReaderOptions.CommentHandling se usan durante la lectura.Hence, JsonReaderOptions.AllowTrailingCommas, JsonReaderOptions.MaxDepth, and JsonReaderOptions.CommentHandling are used while reading.
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
Deserialize<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions)
Analiza el texto con codificación UTF-8 que representa un único valor JSON en una instancia del tipo especificado por un parámetro de tipo genérico.Parses the UTF-8 encoded text representing a single JSON value into an instance of the type specified by a generic type parameter.
public static TValue? Deserialize<TValue> (ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions? options = default);
public static TValue Deserialize<TValue> (ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions options = default);
static member Deserialize : ReadOnlySpan<byte> * System.Text.Json.JsonSerializerOptions -> 'Value
Public Shared Function Deserialize(Of TValue) (utf8Json As ReadOnlySpan(Of Byte), Optional options As JsonSerializerOptions = Nothing) As TValue
Parámetros de tipo
- TValue
Tipo de destino del texto con codificación UTF-8.The target type of the UTF-8 encoded text.
Parámetros
- utf8Json
- ReadOnlySpan<Byte>
Texto JSON que se va a analizar.The JSON text to parse.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento durante el análisis.Options to control the behavior during parsing.
Devoluciones
- TValue
Representación TValue del valor JSON.A TValue representation of the JSON value.
Excepciones
El JSON no es válido.The JSON is invalid.
o bien-or-
TValue no es compatible con el JSON.TValue is not compatible with the JSON.
o bien-or-
Hay datos restantes en el intervalo más allá de un único valor JSON.There is remaining data in the span beyond a single JSON value.
No hay ningún JsonConverter compatible para TValue o sus miembros serializables.There is no compatible JsonConverter for TValue or its serializable members.
Comentarios
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
Deserialize<TValue>(String, JsonSerializerOptions)
Analiza el texto que representa un único valor JSON en una instancia del tipo especificado por un parámetro de tipo genérico.Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.
public static TValue? Deserialize<TValue> (string json, System.Text.Json.JsonSerializerOptions? options = default);
public static TValue Deserialize<TValue> (string json, System.Text.Json.JsonSerializerOptions options = default);
static member Deserialize : string * System.Text.Json.JsonSerializerOptions -> 'Value
Public Shared Function Deserialize(Of TValue) (json As String, Optional options As JsonSerializerOptions = Nothing) As TValue
Parámetros de tipo
- TValue
Tipo de destino del valor JSON.The target type of the JSON value.
Parámetros
- json
- String
Texto JSON que se va a analizar.The JSON text to parse.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento durante el análisis.Options to control the behavior during parsing.
Devoluciones
- TValue
Representación TValue del valor JSON.A TValue representation of the JSON value.
Excepciones
json es null.json is null.
El JSON no es válido.The JSON is invalid.
o bien-or-
TValue no es compatible con el JSON.TValue is not compatible with the JSON.
o bien-or-
Hay datos restantes en el intervalo más allá de un único valor JSON.There is remaining data in the string beyond a single JSON value.
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 los métodos UTF-8, ya que la implementación de utiliza de forma nativa UTF-8.Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
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
Deserialize<TValue>(Utf8JsonReader, JsonSerializerOptions)
Lee un valor JSON (incluidos objetos o matrices) desde el lector proporcionado en una instancia del tipo especificado por un parámetro de tipo genérico.Reads one JSON value (including objects or arrays) from the provided reader into an instance of the type specified by a generic type parameter.
public static TValue? Deserialize<TValue> (ref System.Text.Json.Utf8JsonReader? reader, System.Text.Json.JsonSerializerOptions? options = default);
public static TValue Deserialize<TValue> (ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions options = default);
static member Deserialize : Utf8JsonReader * System.Text.Json.JsonSerializerOptions -> 'Value
Public Shared Function Deserialize(Of TValue) (ByRef reader As Utf8JsonReader, Optional options As JsonSerializerOptions = Nothing) As TValue
Parámetros de tipo
- TValue
Tipo de destino del valor JSON.The target type of the JSON value.
Parámetros
- reader
- Utf8JsonReader
Lector desde el que se va a leer el JSON.The reader to read the JSON from.
- options
- JsonSerializerOptions
Opciones para controlar el comportamiento del serializador durante la lectura.Options to control serializer behavior during reading.
Devoluciones
- TValue
Representación TValue del valor JSON.A TValue representation of the JSON value.
Excepciones
El JSON no es válido.The JSON is invalid.
o bien-or-
TValue no es compatible con el JSON.TValue is not compatible with the JSON.
o bien-or-
No se pudo leer un valor del lector.A value could not be read from the reader.
reader usa opciones no compatibles.reader uses unsupported options.
No hay ningún JsonConverter compatible para TValue o sus miembros serializables.There is no compatible JsonConverter for TValue or its serializable members.
Comentarios
Si la TokenType propiedad de reader es JsonTokenType.PropertyName o JsonTokenType.None , el lector estará avanzado mediante una llamada a Utf8JsonReader.Read() para determinar el inicio del valor.If the TokenType property of reader is JsonTokenType.PropertyName or JsonTokenType.None, the reader will be advanced by one call to Utf8JsonReader.Read() to determine the start of the value.
Tras completar este método, se reader colocará en el token final del valor JSON.Upon completion of this method, reader will be positioned at the final token in the JSON value. Si se produce una excepción, el lector se restablece al estado en que se encontraba cuando se llamó al método.If an exception is thrown, the reader is reset to the state it was in when the method was called.
Este método realiza una copia de los datos en los que se actuó el lector, por lo que no hay ningún requisito del llamador para mantener la integridad de los datos más allá de la devolución de este método.This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
JsonReaderOptionsQue se usa para crear la instancia de Utf8JsonReader tiene prioridad sobre el JsonSerializerOptions cuando entran en conflicto.The JsonReaderOptions used to create the instance of the Utf8JsonReader take precedence over the JsonSerializerOptions when they conflict. Por lo tanto,, JsonReaderOptions.AllowTrailingCommas JsonReaderOptions.MaxDepth y JsonReaderOptions.CommentHandling se usan durante la lectura.Hence, JsonReaderOptions.AllowTrailingCommas, JsonReaderOptions.MaxDepth, and JsonReaderOptions.CommentHandling are used while reading.
Para obtener más información, vea Cómo serializar y deserializar JSON.For more information, see How to serialize and deserialize JSON.