JsonSerializer.DeserializeAsync 方法

定義

多載

DeserializeAsync(Stream, Type, JsonSerializerContext, CancellationToken)

將代表單一 JSON 值的 UTF-8 編碼文字讀入 returnType 。 Stream 將會讀取為完成。

DeserializeAsync(Stream, JsonTypeInfo, CancellationToken)

將代表單一 JSON 值的 UTF-8 編碼文字讀取到 所 jsonTypeInfo 指定的實例。 Stream 將會讀取為完成。

DeserializeAsync(Stream, Type, JsonSerializerOptions, CancellationToken)

將代表單一 JSON 值的 UTF-8 編碼文字,以非同步方式讀取到指定類型的執行個體中。 資料流將會讀取至完成。

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

將代表單一 JSON 值的 UTF-8 編碼文字讀入 TValue 。 Stream 將會讀取為完成。

DeserializeAsync<TValue>(Stream, JsonSerializerOptions, CancellationToken)

將表示單一 JSON 值的 UTF-8 編碼文字,以非同步方式讀取到泛型型別參數所指定類型的執行個體中。 資料流將會讀取至完成。

DeserializeAsync(Stream, Type, JsonSerializerContext, CancellationToken)

來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs

將代表單一 JSON 值的 UTF-8 編碼文字讀入 returnType 。 Stream 將會讀取為完成。

public static System.Threading.Tasks.ValueTask<object?> DeserializeAsync (System.IO.Stream utf8Json, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default);
static member DeserializeAsync : System.IO.Stream * Type * System.Text.Json.Serialization.JsonSerializerContext * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<obj>
Public Function DeserializeAsync (utf8Json As Stream, returnType As Type, context As JsonSerializerContext, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Object)

參數

utf8Json
Stream

要剖析的 JSON 資料。

returnType
Type

要轉換並傳回的物件類型。

context
JsonSerializerContext

可序列化類型的中繼資料提供者。

cancellationToken
CancellationToken

CancellationToken可用來取消讀取作業的 。

傳回

JSON 值的 returnType 表示法。

例外狀況

utf8JsonreturnTypecontextnull

JSON 無效、 returnType 與 JSON 不相容,或 Stream 中有剩餘的資料。

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

GetTypeInfo(Type)提供的 context 方法未傳回 與 returnType 相容的 JsonTypeInfo

解除標記已取消。 此例外狀況會儲存在傳回的工作中。

備註

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException 仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 Deserialize(Stream, Type, JsonSerializerContext) 例外狀況。

適用於

DeserializeAsync(Stream, JsonTypeInfo, CancellationToken)

來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs

將代表單一 JSON 值的 UTF-8 編碼文字讀取到 所 jsonTypeInfo 指定的實例。 Stream 將會讀取為完成。

public static System.Threading.Tasks.ValueTask<object?> DeserializeAsync (System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default);
static member DeserializeAsync : System.IO.Stream * System.Text.Json.Serialization.Metadata.JsonTypeInfo * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<obj>
Public Function DeserializeAsync (utf8Json As Stream, jsonTypeInfo As JsonTypeInfo, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Object)

參數

utf8Json
Stream

要剖析的 JSON 資料。

jsonTypeInfo
JsonTypeInfo

要轉換之型別的相關中繼資料。

cancellationToken
CancellationToken

CancellationToken可用來取消讀取作業的 。

傳回

JSON 值的 jsonTypeInfo 表示法。

例外狀況

utf8JsonjsonTypeInfonull

JSON 無效,或當 Stream 中有剩餘的資料時。

解除標記已取消。 此例外狀況會儲存在傳回的工作中。

適用於

DeserializeAsync(Stream, Type, JsonSerializerOptions, CancellationToken)

來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs

將代表單一 JSON 值的 UTF-8 編碼文字,以非同步方式讀取到指定類型的執行個體中。 資料流將會讀取至完成。

public static System.Threading.Tasks.ValueTask<object?> DeserializeAsync (System.IO.Stream utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
public static System.Threading.Tasks.ValueTask<object> DeserializeAsync (System.IO.Stream utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions options = default, System.Threading.CancellationToken cancellationToken = default);
static member DeserializeAsync : System.IO.Stream * Type * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<obj>
Public Shared Function DeserializeAsync (utf8Json As Stream, returnType As Type, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Object)
Public Function DeserializeAsync (utf8Json As Stream, returnType As Type, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Object)

參數

utf8Json
Stream

要剖析的 JSON 資料。

returnType
Type

要轉換並傳回的物件類型。

options
JsonSerializerOptions

在讀取期間控制行為的選項。

cancellationToken
CancellationToken

可用來取消讀取作業的取消語彙基元。

傳回

JSON 值的 returnType 表示法。

例外狀況

utf8JsonreturnTypenull

JSON 無效。

-或-

TValue 與 JSON 不相容。

-或-

資料流中有剩餘的資料。

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

解除標記已取消。 此例外狀況會儲存在傳回的工作中。

備註

如需詳細資訊,請參閱 如何序列化和還原序列化 JSON

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException 仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 Deserialize(Stream, Type, JsonSerializerOptions) 例外狀況。

適用於

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

來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs

將代表單一 JSON 值的 UTF-8 編碼文字讀入 TValue 。 Stream 將會讀取為完成。

public static System.Threading.Tasks.ValueTask<TValue?> DeserializeAsync<TValue> (System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default);
static member DeserializeAsync : System.IO.Stream * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Value>
Public Function DeserializeAsync(Of TValue) (utf8Json As Stream, jsonTypeInfo As JsonTypeInfo(Of TValue), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TValue)

類型參數

TValue

要還原序列化 JSON 值的型別。

參數

utf8Json
Stream

要剖析的 JSON 資料。

jsonTypeInfo
JsonTypeInfo<TValue>

要轉換之型別的相關中繼資料。

cancellationToken
CancellationToken

CancellationToken 可用來取消讀取作業。

傳回

ValueTask<TValue>

JSON 值的 TValue 表示法。

例外狀況

utf8JsonjsonTypeInfonull

JSON 無效、 TValue 與 JSON 不相容,或 Stream 中有剩餘的資料。

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

解除標記已取消。 此例外狀況會儲存在傳回的工作中。

適用於

DeserializeAsync<TValue>(Stream, JsonSerializerOptions, CancellationToken)

來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs
來源:
JsonSerializer.Read.Stream.cs

將表示單一 JSON 值的 UTF-8 編碼文字,以非同步方式讀取到泛型型別參數所指定類型的執行個體中。 資料流將會讀取至完成。

public static System.Threading.Tasks.ValueTask<TValue?> DeserializeAsync<TValue> (System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
public static System.Threading.Tasks.ValueTask<TValue> DeserializeAsync<TValue> (System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions options = default, System.Threading.CancellationToken cancellationToken = default);
static member DeserializeAsync : System.IO.Stream * System.Text.Json.JsonSerializerOptions * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Value>
Public Shared Function DeserializeAsync(Of TValue) (utf8Json As Stream, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TValue)
Public Function DeserializeAsync(Of TValue) (utf8Json As Stream, Optional options As JsonSerializerOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TValue)

類型參數

TValue

JSON 值的目標型別。

參數

utf8Json
Stream

要剖析的 JSON 資料。

options
JsonSerializerOptions

在讀取期間控制行為的選項。

cancellationToken
CancellationToken

可用來取消讀取作業的語彙基元。

傳回

ValueTask<TValue>

JSON 值的 TValue 表示法。

例外狀況

JSON 無效。

-或-

TValue 與 JSON 不相容。

-或-

資料流中有剩餘的資料。

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

utf8Jsonnull

解除標記已取消。 此例外狀況會儲存在傳回的工作中。

備註

如需詳細資訊,請參閱 如何序列化和還原序列化 JSON

適用於