JsonSerializer.Deserialize Method

Definition

Overloads

Deserialize(Stream, JsonTypeInfo)

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.

Deserialize(Utf8JsonReader, Type, JsonSerializerContext)

Reads one JSON value (including objects or arrays) from the provided reader into a returnType.

Deserialize(JsonNode, Type, JsonSerializerContext)

Converts the JsonNode representing a single JSON value into a returnType.

Deserialize(JsonNode, Type, JsonSerializerOptions)

Converts the JsonNode representing a single JSON value into a returnType.

Deserialize(JsonElement, Type, JsonSerializerContext)

Converts the JsonElement representing a single JSON value into a returnType.

Deserialize(JsonElement, Type, JsonSerializerOptions)

Converts the JsonElement representing a single JSON value into a returnType.

Deserialize(JsonDocument, Type, JsonSerializerContext)

Converts the JsonDocument representing a single JSON value into a returnType.

Deserialize(JsonDocument, Type, JsonSerializerOptions)

Converts the JsonDocument representing a single JSON value into a returnType.

Deserialize(String, Type, JsonSerializerContext)

Parses the text representing a single JSON value into a returnType.

Deserialize(String, Type, JsonSerializerOptions)

Parses the text representing a single JSON value into an instance of a specified type.

Deserialize(ReadOnlySpan<Char>, Type, JsonSerializerContext)

Parses the text representing a single JSON value into a returnType.

Deserialize(ReadOnlySpan<Char>, Type, JsonSerializerOptions)

Parses the text representing a single JSON value into an instance of a specified type.

Deserialize(Utf8JsonReader, Type, JsonSerializerOptions)

Reads one JSON value (including objects or arrays) from the provided reader and converts it into an instance of a specified type.

Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerOptions)

Parses the UTF-8 encoded text representing a single JSON value into an instance of a specified type.

Deserialize(Stream, Type, JsonSerializerContext)

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

Deserialize(Stream, Type, JsonSerializerOptions)

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

Deserialize(Utf8JsonReader, JsonTypeInfo)

Reads one JSON value (including objects or arrays) from the provided reader into an instance specified by the jsonTypeInfo.

Deserialize(JsonNode, JsonTypeInfo)

Converts the JsonNode representing a single JSON value into an instance specified by the jsonTypeInfo.

Deserialize(JsonElement, JsonTypeInfo)

Converts the JsonElement representing a single JSON value into an instance specified by the jsonTypeInfo.

Deserialize(JsonDocument, JsonTypeInfo)

Converts the JsonDocument representing a single JSON value into an instance specified by the jsonTypeInfo.

Deserialize(String, JsonTypeInfo)

Parses the text representing a single JSON value into an instance specified by the jsonTypeInfo.

Deserialize(ReadOnlySpan<Char>, JsonTypeInfo)

Parses the text representing a single JSON value into an instance specified by the jsonTypeInfo.

Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerContext)

Parses the UTF-8 encoded text representing a single JSON value into a returnType.

Deserialize(ReadOnlySpan<Byte>, JsonTypeInfo)

Parses the UTF-8 encoded text representing a single JSON value into an instance specified by the jsonTypeInfo.

Deserialize<TValue>(JsonElement, JsonSerializerOptions)

Converts the JsonElement representing a single JSON value into a TValue.

Deserialize<TValue>(JsonElement, JsonTypeInfo<TValue>)

Converts the JsonElement representing a single JSON value into a TValue.

Deserialize<TValue>(Utf8JsonReader, JsonTypeInfo<TValue>)

Reads one JSON value (including objects or arrays) from the provided reader into a TValue.

Deserialize<TValue>(JsonNode, JsonTypeInfo<TValue>)

Converts the JsonNode representing a single JSON value into a TValue.

Deserialize<TValue>(Utf8JsonReader, JsonSerializerOptions)

Reads one JSON value (including objects or arrays) from the provided reader into an instance of the type specified by a generic type parameter.

Deserialize<TValue>(JsonDocument, JsonTypeInfo<TValue>)

Converts the JsonDocument representing a single JSON value into a TValue.

Deserialize<TValue>(JsonNode, JsonSerializerOptions)

Converts the JsonNode representing a single JSON value into a TValue.

Deserialize<TValue>(JsonDocument, JsonSerializerOptions)

Converts the JsonDocument representing a single JSON value into a TValue.

Deserialize<TValue>(ReadOnlySpan<Char>, JsonTypeInfo<TValue>)

Parses the text representing a single JSON value into a TValue.

Deserialize<TValue>(String, JsonSerializerOptions)

Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.

Deserialize<TValue>(ReadOnlySpan<Char>, JsonSerializerOptions)

Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.

Deserialize<TValue>(ReadOnlySpan<Byte>, JsonTypeInfo<TValue>)

Parses the UTF-8 encoded text representing a single JSON value into a TValue.

Deserialize<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions)

Parses the UTF-8 encoded text representing a single JSON value into an instance of the type specified by a generic type parameter.

Deserialize<TValue>(Stream, JsonTypeInfo<TValue>)

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

Deserialize<TValue>(Stream, JsonSerializerOptions)

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

Deserialize<TValue>(String, JsonTypeInfo<TValue>)

Parses the text representing a single JSON value into a TValue.

Deserialize(Stream, JsonTypeInfo)

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.

C#
public static object? Deserialize (System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

utf8Json
Stream

JSON data to parse.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

utf8Json or jsonTypeInfo is null.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(Utf8JsonReader, Type, JsonSerializerContext)

Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs

Reads one JSON value (including objects or arrays) from the provided reader into a returnType.

C#
public static object? Deserialize (ref System.Text.Json.Utf8JsonReader reader, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

reader
Utf8JsonReader

The reader to read.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

A returnType representation of the JSON value.

Exceptions

returnType or context is null.

The JSON is invalid, returnType is not compatible with the JSON, or a value could not be read from the reader.

reader is using unsupported options.

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.

Remarks

If the TokenType property of reader is PropertyName or None, the reader will be advanced by one call to Read() to determine the start of the value.

Upon completion of this method, reader is positioned at the final token in the JSON value. If an exception is thrown, the reader is reset to the state it was in when the method was called.

This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.

The JsonReaderOptions used to create the instance of the Utf8JsonReader take precedence over the JsonSerializerOptions when they conflict. Hence, AllowTrailingCommas, MaxDepth, and CommentHandling are used while reading.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonNode, Type, JsonSerializerContext)

Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs

Converts the JsonNode representing a single JSON value into a returnType.

C#
public static object? Deserialize (this System.Text.Json.Nodes.JsonNode? node, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

node
JsonNode

The JsonNode to convert.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is null.

-or-

context is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

The GetTypeInfo(Type) method of the provided context returns null for the type to convert.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonNode, Type, JsonSerializerOptions)

Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs

Converts the JsonNode representing a single JSON value into a returnType.

C#
public static object? Deserialize (this System.Text.Json.Nodes.JsonNode? node, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);

Parameters

node
JsonNode

The JsonNode to convert.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonElement, Type, JsonSerializerContext)

Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs

Converts the JsonElement representing a single JSON value into a returnType.

C#
public static object? Deserialize (this System.Text.Json.JsonElement element, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

element
JsonElement

The JsonElement to convert.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is null.

-or-

context is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

The GetTypeInfo(Type) method of the provided context returns null for the type to convert.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonElement, Type, JsonSerializerOptions)

Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs

Converts the JsonElement representing a single JSON value into a returnType.

C#
public static object? Deserialize (this System.Text.Json.JsonElement element, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);

Parameters

element
JsonElement

The JsonElement to convert.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is null.

returnType is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonDocument, Type, JsonSerializerContext)

Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs

Converts the JsonDocument representing a single JSON value into a returnType.

C#
public static object? Deserialize (this System.Text.Json.JsonDocument document, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

document
JsonDocument

The JsonDocument to convert.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

A returnType representation of the JSON value.

Exceptions

document is null.

-or-

returnType is null.

-or-

context is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

The GetTypeInfo(Type) method of the provided context returns null for the type to convert.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonDocument, Type, JsonSerializerOptions)

Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs

Converts the JsonDocument representing a single JSON value into a returnType.

C#
public static object? Deserialize (this System.Text.Json.JsonDocument document, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);

Parameters

document
JsonDocument

The JsonDocument to convert.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType representation of the JSON value.

Exceptions

document or returnType is null.

returnType is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(String, Type, JsonSerializerContext)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into a returnType.

C#
public static object? Deserialize (string json, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

json
String

JSON text to parse.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

A returnType representation of the JSON value.

Exceptions

json or returnType is null.

-or-

context is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

The GetTypeInfo(Type) method of the provided context returns null for the type to convert.

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(String, Type, JsonSerializerOptions)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into an instance of a specified type.

C#
public static object? Deserialize (string json, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static object Deserialize (string json, Type returnType, System.Text.Json.JsonSerializerOptions options = default);

Parameters

json
String

The JSON text to parse.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType representation of the JSON value.

Exceptions

json or returnType is null.

The JSON is invalid.

-or-

TValue is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

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

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 3.0, Core 3.1, 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)

Deserialize(ReadOnlySpan<Char>, Type, JsonSerializerContext)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into a returnType.

C#
public static object? Deserialize (ReadOnlySpan<char> json, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

json
ReadOnlySpan<Char>

JSON text to parse.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

A returnType representation of the JSON value.

Exceptions

json or returnType is null.

-or-

context is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

The GetTypeInfo(Type) method of the provided context returns null for the type to convert.

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(ReadOnlySpan<Char>, Type, JsonSerializerOptions)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into an instance of a specified type.

C#
public static object? Deserialize (ReadOnlySpan<char> json, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);

Parameters

json
ReadOnlySpan<Char>

The JSON text to parse.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

There is remaining data in the span beyond a single JSON value.

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

Remarks

Using a UTF-16 span is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(Utf8JsonReader, Type, JsonSerializerOptions)

Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs

Reads one JSON value (including objects or arrays) from the provided reader and converts it into an instance of a specified type.

C#
public static object? Deserialize (ref System.Text.Json.Utf8JsonReader reader, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static object Deserialize (ref System.Text.Json.Utf8JsonReader reader, Type returnType, System.Text.Json.JsonSerializerOptions options = default);

Parameters

reader
Utf8JsonReader

The reader to read the JSON from.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the serializer behavior during reading.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

A value could not be read from the reader.

reader is using unsupported options.

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

Remarks

If the TokenType property of reader is JsonTokenType.PropertyName or JsonTokenType.None, the reader will be advanced by one call to Utf8JsonReader.Read() to determine the start of the value.

Upon completion of this method, reader will be positioned at the final token in the JSON value. If an exception is thrown, the reader is reset to the state it was in when the method was called.

This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.

The JsonReaderOptions used to create the instance of the Utf8JsonReader take precedence over the JsonSerializerOptions when they conflict. Hence, JsonReaderOptions.AllowTrailingCommas, JsonReaderOptions.MaxDepth, and JsonReaderOptions.CommentHandling are used while reading.

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

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 3.0, Core 3.1, 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)

Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerOptions)

Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs

Parses the UTF-8 encoded text representing a single JSON value into an instance of a specified type.

C#
public static object? Deserialize (ReadOnlySpan<byte> utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static object Deserialize (ReadOnlySpan<byte> utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions options = default);

Parameters

utf8Json
ReadOnlySpan<Byte>

The JSON text to parse.

returnType
Type

The type of the object to convert to and return.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is null.

The JSON is invalid.

-or-

returnType is not compatible with the JSON.

-or-

There is remaining data in the span beyond a single JSON value.

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

Remarks

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

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 3.0, Core 3.1, 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)

Deserialize(Stream, Type, JsonSerializerContext)

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.

C#
public static object? Deserialize (System.IO.Stream utf8Json, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

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.

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.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(Stream, Type, JsonSerializerOptions)

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.

C#
public static object? Deserialize (System.IO.Stream utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions? options = default);

Parameters

utf8Json
Stream

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.

Returns

A returnType representation of the JSON value.

Exceptions

utf8Json or returnType 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.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(Utf8JsonReader, JsonTypeInfo)

Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs

Reads one JSON value (including objects or arrays) from the provided reader into an instance specified by the jsonTypeInfo.

C#
public static object? Deserialize (ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

reader
Utf8JsonReader

The reader to read.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

The JSON is invalid, jsonTypeInfo is not compatible with the JSON, or a value could not be read from the reader.

reader is using unsupported options.

Remarks

If the TokenType property of reader is PropertyName or None, the reader will be advanced by one call to Read() to determine the start of the value.

Upon completion of this method, reader will be positioned at the final token in the JSON value. If an exception is thrown, the reader is reset to the state it was in when the method was called.

This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.

The JsonReaderOptions used to create the instance of the Utf8JsonReader take precedence over the JsonSerializerOptions when they conflict. Hence, AllowTrailingCommas, MaxDepth, and CommentHandling are used while reading.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonNode, JsonTypeInfo)

Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs

Converts the JsonNode representing a single JSON value into an instance specified by the jsonTypeInfo.

C#
public static object? Deserialize (this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

node
JsonNode

The JsonNode to convert.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

jsonTypeInfo is null.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonElement, JsonTypeInfo)

Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs

Converts the JsonElement representing a single JSON value into an instance specified by the jsonTypeInfo.

C#
public static object? Deserialize (this System.Text.Json.JsonElement element, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

element
JsonElement

The JsonElement to convert.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

jsonTypeInfo is null.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(JsonDocument, JsonTypeInfo)

Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs

Converts the JsonDocument representing a single JSON value into an instance specified by the jsonTypeInfo.

C#
public static object? Deserialize (this System.Text.Json.JsonDocument document, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

document
JsonDocument

The JsonDocument to convert.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

document is null.

-or-

jsonTypeInfo is null.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(String, JsonTypeInfo)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into an instance specified by the jsonTypeInfo.

C#
public static object? Deserialize (string json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

json
String

JSON text to parse.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

json is null.

-or-

jsonTypeInfo is null.

The JSON is invalid.

-or-

There is remaining data in the string beyond a single JSON value.

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(ReadOnlySpan<Char>, JsonTypeInfo)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into an instance specified by the jsonTypeInfo.

C#
public static object? Deserialize (ReadOnlySpan<char> json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

json
ReadOnlySpan<Char>

JSON text to parse.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

jsonTypeInfo is null.

The JSON is invalid.

-or-

There is remaining data in the string beyond a single JSON value.

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerContext)

Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs

Parses the UTF-8 encoded text representing a single JSON value into a returnType.

C#
public static object? Deserialize (ReadOnlySpan<byte> utf8Json, Type returnType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

utf8Json
ReadOnlySpan<Byte>

JSON text to parse.

returnType
Type

The type of the object to convert to and return.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

A returnType representation of the JSON value.

Exceptions

returnType is null.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize(ReadOnlySpan<Byte>, JsonTypeInfo)

Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs

Parses the UTF-8 encoded text representing a single JSON value into an instance specified by the jsonTypeInfo.

C#
public static object? Deserialize (ReadOnlySpan<byte> utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

utf8Json
ReadOnlySpan<Byte>

JSON text to parse.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

A jsonTypeInfo representation of the JSON value.

Exceptions

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(JsonElement, JsonSerializerOptions)

Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs

Converts the JsonElement representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (this System.Text.Json.JsonElement element, System.Text.Json.JsonSerializerOptions? options = default);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

element
JsonElement

The JsonElement to convert.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

TValue is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(JsonElement, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs
Source:
JsonSerializer.Read.Element.cs

Converts the JsonElement representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (this System.Text.Json.JsonElement element, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

element
JsonElement

The JsonElement to convert.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

jsonTypeInfo is null.

TValue is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(Utf8JsonReader, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs

Reads one JSON value (including objects or arrays) from the provided reader into a TValue.

C#
public static TValue? Deserialize<TValue> (ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

reader
Utf8JsonReader

The reader to read.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

The JSON is invalid, TValue is not compatible with the JSON, or a value could not be read from the reader.

reader is using unsupported options.

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

Remarks

If the TokenType property of reader is PropertyName or None, the reader will be advanced by one call to Read() to determine the start of the value.

Upon completion of this method, reader is positioned at the final token in the JSON value. If an exception is thrown, the reader is reset to the state it was in when the method was called.

This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.

The JsonReaderOptions used to create the instance of the Utf8JsonReader take precedence over the JsonSerializerOptions when they conflict. Hence, AllowTrailingCommas, MaxDepth, and CommentHandling are used while reading.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(JsonNode, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs

Converts the JsonNode representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

node
JsonNode

The JsonNode to convert.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

jsonTypeInfo is null.

TValue is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(Utf8JsonReader, JsonSerializerOptions)

Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs
Source:
JsonSerializer.Read.Utf8JsonReader.cs

Reads one JSON value (including objects or arrays) from the provided reader into an instance of the type specified by a generic type parameter.

C#
public static TValue? Deserialize<TValue> (ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static TValue Deserialize<TValue> (ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions options = default);

Type Parameters

TValue

The target type of the JSON value.

Parameters

reader
Utf8JsonReader

The reader to read the JSON from.

options
JsonSerializerOptions

Options to control serializer behavior during reading.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

The JSON is invalid.

-or-

TValue is not compatible with the JSON.

-or-

A value could not be read from the reader.

reader uses unsupported options.

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

Remarks

If the TokenType property of reader is JsonTokenType.PropertyName or JsonTokenType.None, the reader will be advanced by one call to Utf8JsonReader.Read() to determine the start of the value.

Upon completion of this method, reader will be positioned at the final token in the JSON value. If an exception is thrown, the reader is reset to the state it was in when the method was called.

This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.

The JsonReaderOptions used to create the instance of the Utf8JsonReader take precedence over the JsonSerializerOptions when they conflict. Hence, JsonReaderOptions.AllowTrailingCommas, JsonReaderOptions.MaxDepth, and JsonReaderOptions.CommentHandling are used while reading.

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

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 3.0, Core 3.1, 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)

Deserialize<TValue>(JsonDocument, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs

Converts the JsonDocument representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (this System.Text.Json.JsonDocument document, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

document
JsonDocument

The JsonDocument to convert.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

document is null.

-or-

jsonTypeInfo is null.

TValue is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(JsonNode, JsonSerializerOptions)

Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs
Source:
JsonSerializer.Read.Node.cs

Converts the JsonNode representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.JsonSerializerOptions? options = default);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

node
JsonNode

The JsonNode to convert.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

TValue is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(JsonDocument, JsonSerializerOptions)

Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs
Source:
JsonSerializer.Read.Document.cs

Converts the JsonDocument representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (this System.Text.Json.JsonDocument document, System.Text.Json.JsonSerializerOptions? options = default);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

document
JsonDocument

The JsonDocument to convert.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

document is null.

TValue is not compatible with the JSON.

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

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(ReadOnlySpan<Char>, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (ReadOnlySpan<char> json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

json
ReadOnlySpan<Char>

JSON text to parse.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

json is null.

-or-

jsonTypeInfo is null.

The JSON is invalid.

-or-

TValue is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(String, JsonSerializerOptions)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.

C#
public static TValue? Deserialize<TValue> (string json, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static TValue Deserialize<TValue> (string json, System.Text.Json.JsonSerializerOptions options = default);

Type Parameters

TValue

The target type of the JSON value.

Parameters

json
String

The JSON text to parse.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

json is null.

The JSON is invalid.

-or-

TValue is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

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

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 3.0, Core 3.1, 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)

Deserialize<TValue>(ReadOnlySpan<Char>, JsonSerializerOptions)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.

C#
public static TValue? Deserialize<TValue> (ReadOnlySpan<char> json, System.Text.Json.JsonSerializerOptions? options = default);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

json
ReadOnlySpan<Char>

The JSON text to parse.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

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 span beyond a single JSON value.

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

Remarks

Using a UTF-16 span is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(ReadOnlySpan<Byte>, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs

Parses the UTF-8 encoded text representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (ReadOnlySpan<byte> utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

utf8Json
ReadOnlySpan<Byte>

JSON text to parse.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

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.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions)

Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs
Source:
JsonSerializer.Read.Span.cs

Parses the UTF-8 encoded text representing a single JSON value into an instance of the type specified by a generic type parameter.

C#
public static TValue? Deserialize<TValue> (ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static TValue Deserialize<TValue> (ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions options = default);

Type Parameters

TValue

The target type of the UTF-8 encoded text.

Parameters

utf8Json
ReadOnlySpan<Byte>

The JSON text to parse.

options
JsonSerializerOptions

Options to control the behavior during parsing.

Returns

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 span beyond a single JSON value.

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

Remarks

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

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 3.0, Core 3.1, 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)

Deserialize<TValue>(Stream, JsonTypeInfo<TValue>)

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.

C#
public static TValue? Deserialize<TValue> (System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

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.

Returns

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.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(Stream, JsonSerializerOptions)

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.

C#
public static TValue? Deserialize<TValue> (System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = default);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

utf8Json
Stream

JSON data to parse.

options
JsonSerializerOptions

Options to control the behavior during reading.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

utf8Json 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.

Applies to

.NET 9 en andere versies
Product Versies
.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)

Deserialize<TValue>(String, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs
Source:
JsonSerializer.Read.String.cs

Parses the text representing a single JSON value into a TValue.

C#
public static TValue? Deserialize<TValue> (string json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type to deserialize the JSON value into.

Parameters

json
String

JSON text to parse.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

TValue

A TValue representation of the JSON value.

Exceptions

json is null.

-or-

jsonTypeInfo is null.

The JSON is invalid.

-or-

TValue is not compatible with the JSON.

-or-

There is remaining data in the string beyond a single JSON value.

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

Remarks

Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.

Applies to

.NET 9 en andere versies
Product Versies
.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)