JsonSerializer.SerializeAsync 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
SerializeAsync(PipeWriter, Object, JsonTypeInfo, CancellationToken)
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- 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可用于取消写入操作的项。
返回
表示异步写入作的任务。
例外
utf8Json 是 null。
value 与类型的 jsonTypeInfo类型不匹配。
适用于
SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken)
将提供的值转换为 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
参数
- value
- Object
要转换的值。
- jsonTypeInfo
- JsonTypeInfo
要转换的类型的元数据。
- cancellationToken
- CancellationToken
CancellationToken可用于取消写入操作的项。
返回
表示异步写入作的任务。
例外
utf8Json 是 null。
value 与类型的 jsonTypeInfo类型不匹配。
取消令牌已取消。 此异常存储在返回的任务中。
适用于
SerializeAsync(PipeWriter, Object, Type, JsonSerializerOptions, CancellationToken)
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- 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可用于取消写入操作的项。
返回
表示异步写入作的任务。
- 属性
例外
inputType 与 value 不兼容。
utf8Json 或 inputType 为 null.
无法与JsonConverter序列化成员或其可序列化成员兼容inputType。
适用于
SerializeAsync(PipeWriter, Object, Type, JsonSerializerContext, CancellationToken)
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- 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可用于取消写入操作的项。
返回
表示异步写入作的任务。
例外
inputType 与 value 不兼容。
utf8Json, inputType或 context 为 null。
无法与JsonConverter序列化成员或其可序列化成员兼容inputType。
适用于
SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken)
将指定类型的值异步转换为 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)
将所提供的值转换为 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
参数
- value
- Object
要转换的值。
- inputType
- Type
要转换的类型 value 。
- context
- JsonSerializerContext
可序列化类型的元数据提供程序。
- cancellationToken
- CancellationToken
CancellationToken可用于取消写入操作的项。
返回
表示异步写入作的任务。
例外
inputType 与 value 不兼容。
utf8Json, inputType或 context 为 null。
无法与JsonConverter序列化成员或其可序列化成员兼容inputType。
取消令牌已取消。 此异常存储在返回的任务中。
注解
此方法存储在任务中,它返回该方法的同步对应项可以引发的所有非使用异常。 如果异常存储在返回的任务中,则等待任务时将引发该异常。 使用情况异常(例如 ArgumentException)仍会同步引发。 有关存储的异常,请参阅由 Serialize(Stream, Object, Type, JsonSerializerContext)..
适用于
SerializeAsync<TValue>(Stream, TValue, JsonTypeInfo<TValue>, CancellationToken)
将所提供的值转换为 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
要序列化的值的类型。
参数
- value
- TValue
要转换的值。
- jsonTypeInfo
- JsonTypeInfo<TValue>
要转换的类型的元数据。
- cancellationToken
- CancellationToken
CancellationToken可用于取消写入操作的项。
返回
表示异步写入作的任务。
例外
utf8Json 是 null。
无法与JsonConverter序列化成员或其可序列化成员兼容TValue。
取消令牌已取消。 此异常存储在返回的任务中。
适用于
SerializeAsync<TValue>(Stream, TValue, JsonSerializerOptions, CancellationToken)
将泛型类型参数指定的类型的值异步转换为 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)
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- 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可用于取消写入操作的项。
返回
表示异步写入作的任务。
例外
utf8Json 是 null。
适用于
SerializeAsync<TValue>(PipeWriter, TValue, JsonSerializerOptions, CancellationToken)
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- JsonSerializer.Write.Pipe.cs
- Source:
- 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可用于取消写入操作的项。
返回
表示异步写入作的任务。
- 属性
例外
utf8Json 是 null。
无法与JsonConverter序列化成员或其可序列化成员兼容TValue。