语言

JsonSerializer.SerializeToUtf8Bytes 方法

定义

重载

名称 说明
SerializeToUtf8Bytes(Object, JsonTypeInfo)

将提供的值转换为 Byte 数组。

SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions)

将指定类型的值转换为 JSON 字符串,编码为 UTF-8 字节。

SerializeToUtf8Bytes(Object, Type, JsonSerializerContext)

将提供的值转换为 Byte 数组。

SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)

将泛型类型参数指定的类型的值转换为 JSON 字符串,编码为 UTF-8 字节。

SerializeToUtf8Bytes<TValue>(TValue, JsonTypeInfo<TValue>)

将提供的值转换为 Byte 数组。

SerializeToUtf8Bytes(Object, JsonTypeInfo)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

将提供的值转换为 Byte 数组。

public:
 static cli::array <System::Byte> ^ SerializeToUtf8Bytes(System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static byte[] SerializeToUtf8Bytes(object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member SerializeToUtf8Bytes : obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> byte[]
Public Function SerializeToUtf8Bytes (value As Object, jsonTypeInfo As JsonTypeInfo) As Byte()

参数

value
Object

要转换的值。

jsonTypeInfo
JsonTypeInfo

要转换的类型的元数据。

返回

Byte[]

值的 UTF-8 表示形式。

例外

jsonTypeInfo 是 null。

value 与类型的 jsonTypeInfo类型不匹配。

适用于

SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

将指定类型的值转换为 JSON 字符串,编码为 UTF-8 字节。

[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 byte[] SerializeToUtf8Bytes(object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = 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 byte[] SerializeToUtf8Bytes(object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static byte[] SerializeToUtf8Bytes(object value, Type inputType, System.Text.Json.JsonSerializerOptions options = 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 SerializeToUtf8Bytes : obj * Type * System.Text.Json.JsonSerializerOptions -> byte[]
static member SerializeToUtf8Bytes : obj * Type * System.Text.Json.JsonSerializerOptions -> byte[]
[<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 SerializeToUtf8Bytes : obj * Type * System.Text.Json.JsonSerializerOptions -> byte[]
Public Function SerializeToUtf8Bytes (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As Byte()
Public Shared Function SerializeToUtf8Bytes (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As Byte()

参数

value
Object

要转换的值。

inputType
Type

要转换的类型 value 。

options
JsonSerializerOptions

用于控制转换行为的选项。

返回

Byte[]

值的 JSON 字符串表示形式,编码为 UTF-8 字节。

属性

例外

inputType 与 value 不兼容。

inputType 是 null。

无法与inputType序列化成员或其可序列化成员兼容JsonConverter。

注解

有关详细信息,请参阅 如何序列化和反序列化 JSON。

适用于

SerializeToUtf8Bytes(Object, Type, JsonSerializerContext)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

将提供的值转换为 Byte 数组。

public:
 static cli::array <System::Byte> ^ SerializeToUtf8Bytes(System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member SerializeToUtf8Bytes : obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> byte[]
Public Function SerializeToUtf8Bytes (value As Object, inputType As Type, context As JsonSerializerContext) As Byte()

参数

value
Object

要转换的值。

inputType
Type

要转换的类型 value 。

context
JsonSerializerContext

可序列化类型的元数据提供程序。

返回

Byte[]

值的 UTF-8 表示形式。

例外

inputType 与 value 不兼容。

inputType 是 null。

无法与inputType序列化成员或其可序列化成员兼容JsonConverter。

GetTypeInfo(Type)为要转换的类型提供的context返回null方法。

适用于

SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

将泛型类型参数指定的类型的值转换为 JSON 字符串,编码为 UTF-8 字节。

[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 byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.JsonSerializerOptions? options = 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 byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.JsonSerializerOptions options = 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 SerializeToUtf8Bytes : 'Value * System.Text.Json.JsonSerializerOptions -> byte[]
static member SerializeToUtf8Bytes : 'Value * System.Text.Json.JsonSerializerOptions -> byte[]
[<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 SerializeToUtf8Bytes : 'Value * System.Text.Json.JsonSerializerOptions -> byte[]
Public Function SerializeToUtf8Bytes(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As Byte()
Public Shared Function SerializeToUtf8Bytes(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As Byte()

类型参数

TValue

值的类型。

参数

value
TValue

要转换的值。

options
JsonSerializerOptions

用于控制转换行为的选项。

返回

Byte[]

值的 JSON 字符串表示形式,编码为 UTF-8 字节。

属性

例外

无法与TValue序列化成员或其可序列化成员兼容JsonConverter。

注解

有关详细信息,请参阅 如何序列化和反序列化 JSON。

适用于

SerializeToUtf8Bytes<TValue>(TValue, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

将提供的值转换为 Byte 数组。

public:
generic <typename TValue>
 static cli::array <System::Byte> ^ SerializeToUtf8Bytes(TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member SerializeToUtf8Bytes : 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> byte[]
Public Function SerializeToUtf8Bytes(Of TValue) (value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue)) As Byte()

类型参数

TValue

要序列化的值的类型。

参数

value
TValue

要转换的值。

jsonTypeInfo
JsonTypeInfo<TValue>

要转换的类型的元数据。

返回

Byte[]

值的 UTF-8 表示形式。

例外

无法与TValue序列化成员或其可序列化成员兼容JsonConverter。

jsonTypeInfo 是 null。

适用于