JsonSerializer.SerializeAsync Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Surcharges
SerializeAsync(Stream, Object, Type, JsonSerializerContext, CancellationToken) |
Convertit la valeur fournie en texte JSON encodé en UTF-8 et l’écrit dans .Stream |
SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken) |
Convertit la valeur fournie en texte JSON encodé en UTF-8 et l’écrit dans .Stream |
SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken) |
Convertit de façon asynchrone la valeur d’un type spécifié en texte JSON encodé en UTF-8 et l’écrit dans le flux spécifié. |
SerializeAsync<TValue>(Stream, TValue, JsonTypeInfo<TValue>, CancellationToken) |
Convertit la valeur fournie en texte JSON encodé en UTF-8 et l’écrit dans .Stream |
SerializeAsync<TValue>(Stream, TValue, JsonSerializerOptions, CancellationToken) |
Convertit de façon asynchrone une valeur d’un type spécifié par un paramètre de type générique en texte JSON encodé en UTF-8 et l’écrit dans un flux. |
SerializeAsync(Stream, Object, Type, JsonSerializerContext, CancellationToken)
Convertit la valeur fournie en texte JSON encodé en UTF-8 et l’écrit dans .Stream
public static System.Threading.Tasks.Task SerializeAsync (System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Stream * obj * Type * System.Text.Json.Serialization.JsonSerializerContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync (utf8Json As Stream, value As Object, inputType As Type, context As JsonSerializerContext, Optional cancellationToken As CancellationToken = Nothing) As Task
Paramètres
- value
- Object
Valeur à convertir.
- inputType
- Type
Type de value
à convertir.
- context
- JsonSerializerContext
Fournisseur de métadonnées pour les types sérialisables.
- cancellationToken
- CancellationToken
CancellationToken qui peut être utilisé pour annuler l’opération d’écriture.
Retours
Tâche qui représente l’opération d’écriture asynchrone.
Exceptions
inputType
n'est pas compatible avec value
.
utf8Json
, inputType
ou context
est null
.
Il n’existe pas de JsonConverter compatible pour inputType
ou ses membres sérialisables.
Le jeton d’annulation a été annulé. Cette exception est stockée dans la tâche retournée.
Remarques
Cette méthode stocke dans la tâche toutes les exceptions de non-utilisation que l’équivalent synchrone de la méthode peut lever. Si une exception est stockée dans la tâche retournée, cette exception sera levée lorsque la tâche est attendue. Les exceptions d’utilisation, telles que ArgumentException, sont toujours levées de manière synchrone. Pour connaître les exceptions stockées, consultez les exceptions levées par Serialize(Stream, Object, Type, JsonSerializerContext).
S’applique à
SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken)
Convertit la valeur fournie en texte JSON encodé en UTF-8 et l’écrit dans .Stream
public static System.Threading.Tasks.Task SerializeAsync (System.IO.Stream utf8Json, object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Stream * obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync (utf8Json As Stream, value As Object, jsonTypeInfo As JsonTypeInfo, Optional cancellationToken As CancellationToken = Nothing) As Task
Paramètres
- value
- Object
La valeur à convertir.
- jsonTypeInfo
- JsonTypeInfo
Métadonnées relatives au type à convertir.
- cancellationToken
- CancellationToken
CancellationToken qui peut être utilisé pour annuler l’opération d’écriture.
Retours
Tâche qui représente l’opération d’écriture asynchrone.
Exceptions
utf8Json
a la valeur null
.
value
ne correspond pas au type de jsonTypeInfo
.
Le jeton d’annulation a été annulé. Cette exception est stockée dans la tâche retournée.
S’applique à
SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken)
Convertit de façon asynchrone la valeur d’un type spécifié en texte JSON encodé en UTF-8 et l’écrit dans le flux spécifié.
public static System.Threading.Tasks.Task SerializeAsync (System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
public static System.Threading.Tasks.Task SerializeAsync (System.IO.Stream utf8Json, object value, Type inputType, System.Text.Json.JsonSerializerOptions options = default, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function SerializeAsync (utf8Json As Stream, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task
Public Function SerializeAsync (utf8Json As Stream, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task
Paramètres
- utf8Json
- Stream
Flux UTF-8 dans lequel écrire.
- value
- Object
Valeur à convertir.
- inputType
- Type
Type de value
à convertir.
- options
- JsonSerializerOptions
Options pour contrôler le comportement de sérialisation.
- cancellationToken
- CancellationToken
Jeton pouvant être utilisé pour annuler l’opération d’écriture.
Retours
Tâche qui représente l’opération d’écriture asynchrone.
Exceptions
inputType
n'est pas compatible avec value
.
utf8Json
ou inputType
est null
.
Il n’existe pas de JsonConverter compatible pour inputType
ou ses membres sérialisables.
Le jeton d’annulation a été annulé. Cette exception est stockée dans la tâche retournée.
Remarques
Pour plus d’informations, consultez Comment sérialiser et désérialiser JSON.
Cette méthode stocke dans la tâche toutes les exceptions de non-utilisation que l’équivalent synchrone de la méthode peut lever. Si une exception est stockée dans la tâche retournée, cette exception sera levée lorsque la tâche est attendue. Les exceptions d’utilisation, telles que ArgumentException, sont toujours levées de manière synchrone. Pour connaître les exceptions stockées, consultez les exceptions levées par Serialize(Stream, Object, Type, JsonSerializerOptions).
S’applique à
SerializeAsync<TValue>(Stream, TValue, JsonTypeInfo<TValue>, CancellationToken)
Convertit la valeur fournie en texte JSON encodé en UTF-8 et l’écrit dans .Stream
public static System.Threading.Tasks.Task SerializeAsync<TValue> (System.IO.Stream utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Stream * 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync(Of TValue) (utf8Json As Stream, value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue), Optional cancellationToken As CancellationToken = Nothing) As Task
Paramètres de type
- TValue
Type de la valeur à sérialiser.
Paramètres
- value
- TValue
La valeur à convertir.
- jsonTypeInfo
- JsonTypeInfo<TValue>
Métadonnées relatives au type à convertir.
- cancellationToken
- CancellationToken
CancellationToken qui peut être utilisé pour annuler l’opération d’écriture.
Retours
Tâche qui représente l’opération d’écriture asynchrone.
Exceptions
utf8Json
a la valeur null
.
Il n’existe pas de JsonConverter compatible pour TValue
ou ses membres sérialisables.
Le jeton d’annulation a été annulé. Cette exception est stockée dans la tâche retournée.
S’applique à
SerializeAsync<TValue>(Stream, TValue, JsonSerializerOptions, CancellationToken)
Convertit de façon asynchrone une valeur d’un type spécifié par un paramètre de type générique en texte JSON encodé en UTF-8 et l’écrit dans un flux.
public static System.Threading.Tasks.Task SerializeAsync<TValue> (System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
public static System.Threading.Tasks.Task SerializeAsync<TValue> (System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions options = default, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function SerializeAsync(Of TValue) (utf8Json As Stream, value As TValue, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task
Public Function SerializeAsync(Of TValue) (utf8Json As Stream, value As TValue, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task
Paramètres de type
- TValue
Type de la valeur à sérialiser.
Paramètres
- utf8Json
- Stream
Flux UTF-8 dans lequel écrire.
- value
- TValue
Valeur à convertir.
- options
- JsonSerializerOptions
Options pour contrôler le comportement de sérialisation.
- cancellationToken
- CancellationToken
Jeton pouvant être utilisé pour annuler l’opération d’écriture.
Retours
Tâche qui représente l’opération d’écriture asynchrone.
Exceptions
utf8Json
a la valeur null
.
Il n’existe pas de JsonConverter compatible pour TValue
ou ses membres sérialisables.
Le jeton d’annulation a été annulé. Cette exception est stockée dans la tâche retournée.
Remarques
Pour plus d’informations, consultez Comment sérialiser et désérialiser JSON.
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de l’année 2024, nous abandonnerons progressivement le mécanisme de retour d’information GitHub Issues pour le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultez :Soumettre et afficher des commentaires pour