JsonSerializer.DeserializeAsync Method

Definition

Overloads

DeserializeAsync(Stream, Type, JsonSerializerOptions, CancellationToken)

Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a specified type. The stream will be read to completion.

DeserializeAsync<TValue>(Stream, JsonSerializerOptions, CancellationToken)

Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a type specified by a generic type parameter. The stream will be read to completion.

DeserializeAsync(Stream, Type, JsonSerializerOptions, CancellationToken)

Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a specified type. The stream will be read to completion.

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)

Parameters

utf8Json
Stream

The JSON data to parse.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the behavior during reading.

cancellationToken
CancellationToken

A cancellation token that may be used to cancel the read operation.

Returns

ValueTask<Object>

A returnType representation of the JSON value.

Exceptions

utf8Json or returnType is null.

The JSON is invalid.

-or-

TValue is not compatible with the JSON.

-or-

There is remaining data in the stream.

There is no compatible JsonConverter for returnType or its serializable members.

Remarks

For more information, see How to serialize and deserialize JSON.

Applies to

DeserializeAsync<TValue>(Stream, JsonSerializerOptions, CancellationToken)

Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a type specified by a generic type parameter. The stream will be read to completion.

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)

Type Parameters

TValue

The target type of the JSON value.

Parameters

utf8Json
Stream

The JSON data to parse.

options
JsonSerializerOptions

Options to control the behavior during reading.

cancellationToken
CancellationToken

A token that may be used to cancel the read operation.

Returns

ValueTask<TValue>

A TValue representation of the JSON value.

Exceptions

The JSON is invalid.

-or-

TValue is not compatible with the JSON.

-or-

There is remaining data in the stream.

There is no compatible JsonConverter for TValue or its serializable members.

utf8Jsonis null.

Remarks

For more information, see How to serialize and deserialize JSON.

Applies to