Breyta

Deila með


JsonSerializer.DeserializeAsync Method

Definition

Overloads

DeserializeAsync(Stream, JsonTypeInfo, CancellationToken)

Reads the UTF-8 encoded text representing a single JSON value into an instance specified by the jsonTypeInfo. 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.

DeserializeAsync(Stream, Type, JsonSerializerContext, CancellationToken)

Reads the UTF-8 encoded text representing a single JSON value into a returnType. The Stream will be read to completion.

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

Reads the UTF-8 encoded text representing a single JSON value into a TValue. 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, JsonTypeInfo, CancellationToken)

Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs

Reads the UTF-8 encoded text representing a single JSON value into an instance specified by the jsonTypeInfo. The Stream will be read to completion.

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)

Parameters

utf8Json
Stream

JSON data to parse.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

cancellationToken
CancellationToken

The CancellationToken that can be used to cancel the read operation.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

utf8Json or jsonTypeInfo is null.

The JSON is invalid, or when there is remaining data in the Stream.

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

DeserializeAsync(Stream, Type, JsonSerializerOptions, CancellationToken)

Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs

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)
Public 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

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.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

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

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Deserialize(Stream, Type, JsonSerializerOptions).

Applies to

DeserializeAsync(Stream, Type, JsonSerializerContext, CancellationToken)

Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs

Reads the UTF-8 encoded text representing a single JSON value into a returnType. The Stream will be read to completion.

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)

Parameters

utf8Json
Stream

JSON data to parse.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

cancellationToken
CancellationToken

The CancellationToken that can be used to cancel the read operation.

Returns

A returnType representation of the JSON value.

Exceptions

utf8Json, returnType, or context is null.

The JSON is invalid, the returnType 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.

The GetTypeInfo(Type) method on the provided context did not return a compatible JsonTypeInfo for returnType.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Deserialize(Stream, Type, JsonSerializerContext).

Applies to

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

Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs

Reads the UTF-8 encoded text representing a single JSON value into a TValue. The Stream will be read to completion.

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)

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

utf8Json
Stream

JSON data to parse.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

cancellationToken
CancellationToken

The CancellationToken which may be used to cancel the read operation.

Returns

ValueTask<TValue>

A TValue representation of the JSON value.

Exceptions

utf8Json or jsonTypeInfo is null.

The JSON is invalid, 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.

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

DeserializeAsync<TValue>(Stream, JsonSerializerOptions, CancellationToken)

Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs
Source:
JsonSerializer.Read.Stream.cs

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)
Public 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.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

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

Applies to