共用方式為


JsonSerializer.SerializeAsync 方法

定義

多載

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

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

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

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

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

以異步方式將指定型別的值轉換為 UTF-8 編碼的 JSON 文字,並將它寫入指定的數據流。

SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken)

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

SerializeAsync(PipeWriter, Object, JsonTypeInfo, CancellationToken)

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

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

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

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

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

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

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

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

以異步方式將泛型型別參數所指定的型別值轉換為UTF-8編碼的JSON文字,並將其寫入數據流。

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

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

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
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(PipeWriter, Object, Type, JsonSerializerContext, CancellationToken)

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

public static System.Threading.Tasks.Task SerializeAsync (System.IO.Pipelines.PipeWriter utf8Json, object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Pipelines.PipeWriter * obj * Type * System.Text.Json.Serialization.JsonSerializerContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync (utf8Json As PipeWriter, value As Object, inputType As Type, context As JsonSerializerContext, Optional cancellationToken As CancellationToken = Nothing) As Task

參數

utf8Json
PipeWriter

要寫入的UTF-8 PipeWriter

value
Object

要轉換的值。

inputType
Type

要轉換的 value 型別。

context
JsonSerializerContext

可串行化類型的元數據提供者。

cancellationToken
CancellationToken

可用來取消寫入作業的 CancellationToken

傳回

表示異步寫入作業的工作。

例外狀況

inputTypevalue不相容。

utf8JsoninputTypecontextnull

沒有相容的 JsonConverter

針對 inputType 或其可串行化的成員。

適用於

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
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(Stream, Object, JsonTypeInfo, CancellationToken)

來源:
JsonSerializer.Write.Stream.cs
來源:
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

傳回

表示異步寫入作業的工作。

例外狀況

utf8Json null

valuejsonTypeInfo的類型不相符。

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

適用於

SerializeAsync(PipeWriter, Object, JsonTypeInfo, CancellationToken)

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

public static System.Threading.Tasks.Task SerializeAsync (System.IO.Pipelines.PipeWriter utf8Json, object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Pipelines.PipeWriter * obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync (utf8Json As PipeWriter, value As Object, jsonTypeInfo As JsonTypeInfo, Optional cancellationToken As CancellationToken = Nothing) As Task

參數

utf8Json
PipeWriter

要寫入的UTF-8 PipeWriter

value
Object

要轉換的值。

jsonTypeInfo
JsonTypeInfo

要轉換之型別的相關元數據。

cancellationToken
CancellationToken

可用來取消寫入作業的 CancellationToken

傳回

表示異步寫入作業的工作。

例外狀況

utf8Json null

valuejsonTypeInfo的類型不相符。

適用於

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

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

public static System.Threading.Tasks.Task SerializeAsync (System.IO.Pipelines.PipeWriter utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Pipelines.PipeWriter * obj * Type * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync (utf8Json As PipeWriter, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task

參數

utf8Json
PipeWriter

要寫入的UTF-8 PipeWriter

value
Object

要轉換的值。

inputType
Type

要轉換的 value 型別。

options
JsonSerializerOptions

控制轉換行為的選項。

cancellationToken
CancellationToken

可用來取消寫入作業的 CancellationToken

傳回

表示異步寫入作業的工作。

例外狀況

inputTypevalue不相容。

utf8JsoninputTypenull

沒有相容的 JsonConverter

針對 inputType 或其可串行化的成員。

適用於

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

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

public static System.Threading.Tasks.Task SerializeAsync<TValue> (System.IO.Pipelines.PipeWriter utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Pipelines.PipeWriter * 'Value * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync(Of TValue) (utf8Json As PipeWriter, value As TValue, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task

類型參數

TValue

要串行化之值的型別。

參數

utf8Json
PipeWriter

要寫入的UTF-8 PipeWriter

value
TValue

要轉換的值。

options
JsonSerializerOptions

控制轉換行為的選項。

cancellationToken
CancellationToken

可用來取消寫入作業的 CancellationToken

傳回

表示異步寫入作業的工作。

例外狀況

utf8Json null

沒有相容的 JsonConverter

針對 TValue 或其可串行化的成員。

適用於

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

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

public static System.Threading.Tasks.Task SerializeAsync<TValue> (System.IO.Pipelines.PipeWriter utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default);
static member SerializeAsync : System.IO.Pipelines.PipeWriter * 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync(Of TValue) (utf8Json As PipeWriter, value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue), Optional cancellationToken As CancellationToken = Nothing) As Task

類型參數

TValue

要串行化之值的型別。

參數

utf8Json
PipeWriter

要寫入的UTF-8 PipeWriter

value
TValue

要轉換的值。

jsonTypeInfo
JsonTypeInfo<TValue>

要轉換之型別的相關元數據。

cancellationToken
CancellationToken

可用來取消寫入作業的 CancellationToken

傳回

表示異步寫入作業的工作。

例外狀況

utf8Json null

適用於

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
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

可用來取消寫入作業的令牌。

傳回

表示異步寫入作業的工作。

例外狀況

utf8Json null

TValue 或其可串行化成員沒有相容的 JsonConverter

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

備註

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

適用於

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
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

傳回

表示異步寫入作業的工作。

例外狀況

utf8Json null

TValue 或其可串行化成員沒有相容的 JsonConverter

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

適用於