JsonSerializer.SerializeToUtf8Bytes 方法

定义

重载

SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions)

将指定类型的值转换为编码为 UTF-8 字节的 JSON 字符串。Converts a value of the specified type into a JSON string, encoded as UTF-8 bytes.

SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)

将泛型类型参数指定的类型的值转换为编码为 UTF-8 字节的 JSON 字符串。Converts the value of a type specified by a generic type parameter into a JSON string, encoded as UTF-8 bytes.

SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions)

将指定类型的值转换为编码为 UTF-8 字节的 JSON 字符串。Converts a value of the specified type into a JSON string, encoded as UTF-8 bytes.

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

参数

value
Object

要转换的值。The value to convert.

inputType
Type

要转换的 value 的类型。The type of the value to convert.

options
JsonSerializerOptions

用于控制转换行为的选项。Options to control the conversion behavior.

返回

Byte[]

值的 JSON 字符串表示形式,编码为 UTF-8 字节。A JSON string representation of the value, encoded as UTF-8 bytes.

例外

inputTypevalue 不兼容。inputType is not compatible with value.

inputTypenullinputType is null.

inputType 或其可序列化成员没有兼容的 JsonConverterThere is no compatible JsonConverter for inputType or its serializable members.

注解

有关详细信息,请参阅 如何序列化和反序列化 JSONFor more information, see How to serialize and deserialize JSON.

适用于

SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)

将泛型类型参数指定的类型的值转换为编码为 UTF-8 字节的 JSON 字符串。Converts the value of a type specified by a generic type parameter into a JSON string, encoded as UTF-8 bytes.

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

类型参数

TValue

值的类型。The type of the value.

参数

value
TValue

要转换的值。The value to convert.

options
JsonSerializerOptions

用于控制转换行为的选项。Options to control the conversion behavior.

返回

Byte[]

值的 JSON 字符串表示形式,编码为 UTF-8 字节。A JSON string representation of the value, encoded as UTF-8 bytes.

例外

TValue 或其可序列化成员没有兼容的 JsonConverterThere is no compatible JsonConverter for TValue or its serializable members.

注解

有关详细信息,请参阅 如何序列化和反序列化 JSONFor more information, see How to serialize and deserialize JSON.

适用于