語言

JsonSerializer.SerializeAsync 方法

定義

多載

名稱 Description
SerializeAsync(PipeWriter, Object, JsonTypeInfo, CancellationToken)

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

SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken)

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

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

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

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

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

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

非同步將指定型別的值轉換為 UTF-8 編碼的 JSON 文字,並寫入指定的串流。

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

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

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

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

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

非同步將由一般型別參數指定的值轉換為 UTF-8 編碼的 JSON 文字,並寫入串流。

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

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

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

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

SerializeAsync(PipeWriter, Object, JsonTypeInfo, CancellationToken)

來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs

將提供的值轉換為 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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

例外狀況

utf8Json 是 null。

value 不符合 的 jsonTypeInfo類型。

適用於

SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken)

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
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, 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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

例外狀況

utf8Json 是 null。

value 不符合 的 jsonTypeInfo類型。

取消令牌也被取消了。 此例外會儲存在回傳的任務中。

適用於

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

來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs

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

[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 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);
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);
[<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 SerializeAsync : System.IO.Pipelines.PipeWriter * obj * Type * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

屬性

例外狀況

inputType 與 value不相容。

utf8Json 或 inputType 為 null。

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

適用於

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

來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs

將提供的值轉換為 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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

例外狀況

inputType 與 value不相容。

utf8Json, , inputType或 context 是 null。

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

適用於

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs

非同步將指定型別的值轉換為 UTF-8 編碼的 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 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);
[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 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);
[<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 SerializeAsync : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
static member SerializeAsync : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
[<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 SerializeAsync : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.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
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

參數

utf8Json
Stream

要寫入的 UTF-8 串流。

value
Object

要轉換的值。

inputType
Type

轉換的類型 value 。

options
JsonSerializerOptions

控制序列化行為的選項。

cancellationToken
CancellationToken

一個可用來取消寫入操作的標記。

傳回

一個代表非同步寫入操作的任務。

屬性

例外狀況

inputType 與 value不相容。

utf8Json 或 inputType 為 null。

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

取消令牌也被取消了。 此例外會儲存在回傳的任務中。

備註

更多資訊請參閱 《如何序列化與反序列化 JSON》。

此方法在任務中儲存所有非使用例外,該方法的同步對應程式可拋出這些例外。 如果回傳的任務中儲存了例外,該例外會在等待任務時拋出。 使用例外錯誤,例如 ArgumentException,仍會同步拋出。 關於儲存的例外,請參見由 Serialize(Stream, Object, Type, JsonSerializerOptions)拋出的例外。

適用於

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

例外狀況

inputType 與 value不相容。

utf8Json, , inputType或 context 是 null。

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

取消令牌也被取消了。 此例外會儲存在回傳的任務中。

備註

此方法在任務中儲存所有非使用例外,該方法的同步對應程式可拋出這些例外。 如果回傳的任務中儲存了例外,該例外會在等待任務時拋出。 使用例外錯誤,例如 ArgumentException,仍會同步拋出。 關於儲存的例外,請參見由 Serialize(Stream, Object, Type, JsonSerializerContext)拋出的例外。

適用於

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

例外狀況

utf8Json 是 null。

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

取消令牌也被取消了。 此例外會儲存在回傳的任務中。

適用於

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

來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs
來源:
JsonSerializer.Write.Stream.cs

非同步將由一般型別參數指定的值轉換為 UTF-8 編碼的 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 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);
[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 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);
[<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 SerializeAsync : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
static member SerializeAsync : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
[<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 SerializeAsync : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SerializeAsync(Of TValue) (utf8Json As Stream, value As TValue, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As 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

類型參數

TValue

要序列化的值類型。

參數

utf8Json
Stream

要寫入的 UTF-8 串流。

value
TValue

要轉換的值。

options
JsonSerializerOptions

控制序列化行為的選項。

cancellationToken
CancellationToken

一個可用來取消寫入操作的標記。

傳回

一個代表非同步寫入操作的任務。

屬性

例外狀況

utf8Json 是 null。

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

取消令牌也被取消了。 此例外會儲存在回傳的任務中。

備註

更多資訊請參閱 《如何序列化與反序列化 JSON》。

適用於

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

來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs

將提供的值轉換為 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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

例外狀況

utf8Json 是 null。

適用於

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

來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs
來源:
JsonSerializer.Write.Pipe.cs

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

[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 System.Threading.Tasks.Task SerializeAsync<TValue>(System.IO.Pipelines.PipeWriter utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
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);
[<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 SerializeAsync : System.IO.Pipelines.PipeWriter * 'Value * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
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可以用 the 來取消寫入操作。

傳回

一個代表非同步寫入操作的任務。

屬性

例外狀況

utf8Json 是 null。

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

適用於