JsonSerializer.SerializeAsync 方法

定義

多載

SerializeAsync(Stream, Object, Type, JsonSerializerContext, CancellationToken)

將所提供的值轉換為 UTF-8 編碼的 JSON 文字,並將其寫入 Stream

SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken)

將所提供的值轉換為 UTF-8 編碼的 JSON 文字,並將它 Stream 寫入 。

SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken)

將指定類型的值,以非同步方式轉換成 UTF-8 編碼的 JSON 文字,並將其寫入指定的資料流。

SerializeAsync<TValue>(Stream, TValue, JsonTypeInfo<TValue>, CancellationToken)

將所提供的值轉換為 UTF-8 編碼的 JSON 文字,並將其寫入 Stream

SerializeAsync<TValue>(Stream, TValue, JsonSerializerOptions, CancellationToken)

將泛型型別參數所指定類型的值,以非同步方式轉換為 UTF-8 編碼的 JSON 文字,並將它寫入資料流。

SerializeAsync(Stream, Object, Type, JsonSerializerContext, CancellationToken)

Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs

將所提供的值轉換為 UTF-8 編碼的 JSON 文字,並將其寫入 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

參數

utf8Json
Stream

要寫入的 UTF-8 Stream

value
Object

要進行轉換的值。

inputType
Type

要轉換的 value 類型。

context
JsonSerializerContext

可序列化類型的中繼資料提供者。

cancellationToken
CancellationToken

CancellationToken可用來取消寫入作業的 。

傳回

表示非同步寫入作業的工作。

例外狀況

inputTypevalue 不相容。

utf8JsoninputTypecontextnull

inputType 或其可序列化成員沒有相容的 JsonConverter

取消權杖已取消。 此例外狀況會儲存在傳回的工作中。

備註

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用狀況例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用狀況例外狀況,例如 ArgumentException ,仍會同步擲回。 如需預存的例外狀況,請參閱 所 Serialize(Stream, Object, Type, JsonSerializerContext) 擲回的例外狀況。

適用於

SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken)

Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs

將所提供的值轉換為 UTF-8 編碼的 JSON 文字,並將它 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

參數

utf8Json
Stream

要寫入的 UTF-8 Stream

value
Object

要進行轉換的值。

jsonTypeInfo
JsonTypeInfo

要轉換之型別的相關中繼資料。

cancellationToken
CancellationToken

CancellationToken可用來取消寫入作業的 。

傳回

表示非同步寫入作業的工作。

例外狀況

utf8Jsonnull

value 不符合 的類型 jsonTypeInfo

取消權杖已取消。 此例外狀況會儲存在傳回的工作中。

適用於

SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken)

Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs

將指定類型的值,以非同步方式轉換成 UTF-8 編碼的 JSON 文字,並將其寫入指定的資料流。

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

參數

utf8Json
Stream

要寫入的 UTF-8 資料流。

value
Object

要進行轉換的值。

inputType
Type

要轉換的 value 類型。

options
JsonSerializerOptions

控制序列化行為的選項。

cancellationToken
CancellationToken

可用來取消寫入作業的語彙基元。

傳回

表示非同步寫入作業的工作。

例外狀況

inputTypevalue 不相容。

utf8JsoninputTypenull

inputType 或其可序列化成員沒有相容的 JsonConverter

取消權杖已取消。 此例外狀況會儲存在傳回的工作中。

備註

如需詳細資訊,請參閱 如何序列化和還原序列化 JSON

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用狀況例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用狀況例外狀況,例如 ArgumentException ,仍會同步擲回。 如需預存的例外狀況,請參閱 所 Serialize(Stream, Object, Type, JsonSerializerOptions) 擲回的例外狀況。

適用於

SerializeAsync<TValue>(Stream, TValue, JsonTypeInfo<TValue>, CancellationToken)

Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs

將所提供的值轉換為 UTF-8 編碼的 JSON 文字,並將其寫入 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

類型參數

TValue

要序列化之值的類型。

參數

utf8Json
Stream

要寫入的 UTF-8 Stream

value
TValue

要進行轉換的值。

jsonTypeInfo
JsonTypeInfo<TValue>

要轉換之型別的相關中繼資料。

cancellationToken
CancellationToken

CancellationToken可用來取消寫入作業的 。

傳回

表示非同步寫入作業的工作。

例外狀況

utf8Jsonnull

TValue 或其可序列化成員沒有相容的 JsonConverter

取消權杖已取消。 此例外狀況會儲存在傳回的工作中。

適用於

SerializeAsync<TValue>(Stream, TValue, JsonSerializerOptions, CancellationToken)

Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs
Source:
JsonSerializer.Write.Stream.cs

將泛型型別參數所指定類型的值,以非同步方式轉換為 UTF-8 編碼的 JSON 文字,並將它寫入資料流。

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

類型參數

TValue

要序列化之值的類型。

參數

utf8Json
Stream

要寫入的 UTF-8 資料流。

value
TValue

要進行轉換的值。

options
JsonSerializerOptions

控制序列化行為的選項。

cancellationToken
CancellationToken

可用來取消寫入作業的語彙基元。

傳回

表示非同步寫入作業的工作。

例外狀況

utf8Jsonnull

TValue 或其可序列化成員沒有相容的 JsonConverter

取消權杖已取消。 此例外狀況會儲存在傳回的工作中。

備註

如需詳細資訊,請參閱 如何序列化和還原序列化 JSON

適用於