HttpContentJsonExtensions.ReadFromJsonAsync Method

Definition

Overloads

ReadFromJsonAsync(HttpContent, Type, CancellationToken)

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

ReadFromJsonAsync(HttpContent, Type, JsonSerializerOptions, CancellationToken)

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

ReadFromJsonAsync(HttpContent, Type, JsonSerializerContext, CancellationToken)

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

ReadFromJsonAsync<T>(HttpContent, CancellationToken)

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

ReadFromJsonAsync<T>(HttpContent, JsonSerializerOptions, CancellationToken)

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

ReadFromJsonAsync<T>(HttpContent, JsonTypeInfo<T>, CancellationToken)

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

ReadFromJsonAsync(HttpContent, Type, CancellationToken)

Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

C#
public static System.Threading.Tasks.Task<object?> ReadFromJsonAsync(this System.Net.Http.HttpContent content, Type type, System.Threading.CancellationToken cancellationToken = default);

Parameters

content
HttpContent

The content to read from.

type
Type

The type of the object to deserialize to and return.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

The task object representing the asynchronous operation.

Exceptions

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

Applies to

.NET 9 and other versions
Product Versions
.NET 8 (package-provided), 8, 9 (package-provided), 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided)

ReadFromJsonAsync(HttpContent, Type, JsonSerializerOptions, CancellationToken)

Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

C#
public static System.Threading.Tasks.Task<object?> ReadFromJsonAsync(this System.Net.Http.HttpContent content, Type type, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
C#
public static System.Threading.Tasks.Task<object?> ReadFromJsonAsync(this System.Net.Http.HttpContent content, Type type, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default);

Parameters

content
HttpContent

The content to read from.

type
Type

The type of the object to deserialize to and return.

options
JsonSerializerOptions

Options to control the behavior during deserialization. The default options are those specified by Web.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

The task object representing the asynchronous operation.

Exceptions

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

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided)

ReadFromJsonAsync(HttpContent, Type, JsonSerializerContext, CancellationToken)

Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

C#
public static System.Threading.Tasks.Task<object?> ReadFromJsonAsync(this System.Net.Http.HttpContent content, Type type, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default);

Parameters

content
HttpContent

The content to read from.

type
Type

The type of the object to deserialize to and return.

context
JsonSerializerContext

The JsonSerializerContext used to control the deserialization behavior.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

The task object representing the asynchronous operation.

Exceptions

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

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8 (package-provided), 8, 9 (package-provided), 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided)

ReadFromJsonAsync<T>(HttpContent, CancellationToken)

Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

C#
public static System.Threading.Tasks.Task<T?> ReadFromJsonAsync<T>(this System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

T

The target type to deserialize to.

Parameters

content
HttpContent

The content to read from.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<T>

The task object representing the asynchronous operation.

Exceptions

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

Applies to

.NET 9 and other versions
Product Versions
.NET 8 (package-provided), 8, 9 (package-provided), 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided)

ReadFromJsonAsync<T>(HttpContent, JsonSerializerOptions, CancellationToken)

Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

C#
public static System.Threading.Tasks.Task<T?> ReadFromJsonAsync<T>(this System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
C#
public static System.Threading.Tasks.Task<T?> ReadFromJsonAsync<T>(this System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

T

The target type to deserialize to.

Parameters

content
HttpContent

The content to read from.

options
JsonSerializerOptions

Options to control the behavior during deserialization. The default options are those specified by Web.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<T>

The task object representing the asynchronous operation.

Exceptions

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

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided)

ReadFromJsonAsync<T>(HttpContent, JsonTypeInfo<T>, CancellationToken)

Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs
Source:
HttpContentJsonExtensions.cs

Reads the HTTP content and returns the value that results from deserializing the content as JSON in an asynchronous operation.

C#
public static System.Threading.Tasks.Task<T?> ReadFromJsonAsync<T>(this System.Net.Http.HttpContent content, System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

T

The target type to deserialize to.

Parameters

content
HttpContent

The content to read from.

jsonTypeInfo
JsonTypeInfo<T>

The JsonTypeInfo used to control the deserialization behavior.

cancellationToken
CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<T>

The task object representing the asynchronous operation.

Exceptions

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

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8 (package-provided), 8, 9 (package-provided), 9
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided)