JsonSerializer.SerializeToUtf8Bytes 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| 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)
將提供的值轉換成陣 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
關於要轉換的類型資料。
傳回
一個 UTF-8 表示值。
例外狀況
jsonTypeInfo 是 null。
value 不符合 的 jsonTypeInfo類型。
適用於
SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions)
將指定類型的值轉換為 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
控制轉換行為的選項。
傳回
一個 JSON 字串表示值,編碼為 UTF-8 位元組。
- 屬性
例外狀況
inputType 與 value不相容。
inputType 是 null。
沒有相容 JsonConverter 的 或 inputType 其可序列化的成員。
備註
更多資訊請參閱 《如何序列化與反序列化 JSON》。
適用於
SerializeToUtf8Bytes(Object, Type, JsonSerializerContext)
將提供的值轉換成陣 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
一個可序列化型別的元資料提供者。
傳回
一個 UTF-8 表示值。
例外狀況
inputType 與 value不相容。
inputType 是 null。
沒有相容 JsonConverter 的 或 inputType 其可序列化的成員。
該 GetTypeInfo(Type) 類型所提供的 context 回報 null 轉換方法。
適用於
SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)
將由一般型別參數指定的型別值轉換成 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
控制轉換行為的選項。
傳回
一個 JSON 字串表示值,編碼為 UTF-8 位元組。
- 屬性
例外狀況
沒有相容 JsonConverter 的 或 TValue 其可序列化的成員。
備註
更多資訊請參閱 《如何序列化與反序列化 JSON》。
適用於
SerializeToUtf8Bytes<TValue>(TValue, JsonTypeInfo<TValue>)
將提供的值轉換成陣 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>
關於要轉換的類型資料。
傳回
一個 UTF-8 表示值。
例外狀況
沒有相容 JsonConverter 的 或 TValue 其可序列化的成員。
jsonTypeInfo 是 null。