JsonSerializer.Deserialize JsonSerializer.Deserialize JsonSerializer.Deserialize Method

Definition

Overloads

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

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

Deserialize(String, Type, JsonSerializerOptions) Deserialize(String, Type, JsonSerializerOptions) Deserialize(String, Type, JsonSerializerOptions)

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

Deserialize(Utf8JsonReader, Type, JsonSerializerOptions) Deserialize(Utf8JsonReader, Type, JsonSerializerOptions) 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<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions) Deserialize<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions) 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>(String, JsonSerializerOptions) Deserialize<TValue>(String, JsonSerializerOptions) 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>(Utf8JsonReader, JsonSerializerOptions) Deserialize<TValue>(Utf8JsonReader, JsonSerializerOptions) 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(ReadOnlySpan<Byte>, Type, JsonSerializerOptions) Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerOptions) Deserialize(ReadOnlySpan<Byte>, Type, JsonSerializerOptions)

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

public static object Deserialize (ReadOnlySpan<byte> utf8Json, Type returnType, System.Text.Json.JsonSerializerOptions options = null);
static member Deserialize : ReadOnlySpan<byte> * Type * System.Text.Json.JsonSerializerOptions -> obj
Public Shared Function Deserialize (utf8Json As ReadOnlySpan(Of Byte), returnType As Type, Optional options As JsonSerializerOptions = null) As Object

Parameters

utf8Json
ReadOnlySpan<Byte>

The JSON text to parse.

returnType
Type Type Type

The type of the object to convert to and return.

options
JsonSerializerOptions JsonSerializerOptions JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType representation of the JSON value.

Exceptions

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.

Deserialize(String, Type, JsonSerializerOptions) Deserialize(String, Type, JsonSerializerOptions) Deserialize(String, Type, JsonSerializerOptions)

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

public static object Deserialize (string json, Type returnType, System.Text.Json.JsonSerializerOptions options = null);
static member Deserialize : string * Type * System.Text.Json.JsonSerializerOptions -> obj
Public Shared Function Deserialize (json As String, returnType As Type, Optional options As JsonSerializerOptions = null) As Object

Parameters

json
String String String

The JSON text to parse.

returnType
Type Type Type

The type of the object to convert to and return.

options
JsonSerializerOptions JsonSerializerOptions JsonSerializerOptions

Options to control the behavior during parsing.

Returns

A returnType 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 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.

Deserialize(Utf8JsonReader, Type, JsonSerializerOptions) Deserialize(Utf8JsonReader, Type, JsonSerializerOptions) 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.

public static object Deserialize (ref System.Text.Json.Utf8JsonReader reader, Type returnType, System.Text.Json.JsonSerializerOptions options = null);
static member Deserialize : Utf8JsonReader * Type * System.Text.Json.JsonSerializerOptions -> obj
Public Shared Function Deserialize (ByRef reader As Utf8JsonReader, returnType As Type, Optional options As JsonSerializerOptions = null) As Object

Parameters

reader
Utf8JsonReader Utf8JsonReader Utf8JsonReader

The reader to read the JSON from.

returnType
Type Type Type

The type of the object to convert to and return.

options
JsonSerializerOptions JsonSerializerOptions JsonSerializerOptions

Options to control the serializer behavior during reading.

Returns

A returnType representation of the JSON value.

Exceptions

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.

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.

Deserialize<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions) Deserialize<TValue>(ReadOnlySpan<Byte>, JsonSerializerOptions) 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.

public static TValue Deserialize<TValue> (ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions options = null);
static member Deserialize : ReadOnlySpan<byte> * System.Text.Json.JsonSerializerOptions -> 'Value
Public Shared Function Deserialize(Of TValue) (utf8Json As ReadOnlySpan(Of Byte), Optional options As JsonSerializerOptions = null) As TValue

Type Parameters

TValue

The target type of the UTF-8 encoded text.

Parameters

utf8Json
ReadOnlySpan<Byte>

The JSON text to parse.

options
JsonSerializerOptions JsonSerializerOptions JsonSerializerOptions

Options to control the behavior during parsing.

Returns

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

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

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

public static TValue Deserialize<TValue> (string json, System.Text.Json.JsonSerializerOptions options = null);
static member Deserialize : string * System.Text.Json.JsonSerializerOptions -> 'Value
Public Shared Function Deserialize(Of TValue) (json As String, Optional options As JsonSerializerOptions = null) As TValue

Type Parameters

TValue

The target type of the JSON value.

Parameters

json
String String String

The JSON text to parse.

options
JsonSerializerOptions JsonSerializerOptions JsonSerializerOptions

Options to control the behavior during parsing.

Returns

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

Deserialize<TValue>(Utf8JsonReader, JsonSerializerOptions) Deserialize<TValue>(Utf8JsonReader, JsonSerializerOptions) 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.

public static TValue Deserialize<TValue> (ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions options = null);
static member Deserialize : Utf8JsonReader * System.Text.Json.JsonSerializerOptions -> 'Value
Public Shared Function Deserialize(Of TValue) (ByRef reader As Utf8JsonReader, Optional options As JsonSerializerOptions = null) As TValue

Type Parameters

TValue

The target type of the JSON value.

Parameters

reader
Utf8JsonReader Utf8JsonReader Utf8JsonReader

The reader to read the JSON from.

options
JsonSerializerOptions JsonSerializerOptions JsonSerializerOptions

Options to control serializer behavior during reading.

Returns

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

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.

Applies to