JsonMediaTypeFormatter

Ecng.Net

A media type formatter for JSON content using System.Text.Json.

Реализует: IMediaTypeFormatter

Конструкторы

JsonMediaTypeFormatter
public JsonMediaTypeFormatter()
jsonMediaTypeFormatter = JsonMediaTypeFormatter()

Initializes a new instance of the JsonMediaTypeFormatter class with default serializer options.

JsonMediaTypeFormatter
public JsonMediaTypeFormatter(JsonSerializerOptions options)
jsonMediaTypeFormatter = JsonMediaTypeFormatter(options)

Initializes a new instance of the JsonMediaTypeFormatter class with the specified serializer options.

options
The JSON serializer options.

Свойства

MediaType
public string MediaType { get; }
value = jsonMediaTypeFormatter.MediaType

Gets the media type this formatter handles (e.g. "application/json").

Options
public JsonSerializerOptions Options { get; set; }
value = jsonMediaTypeFormatter.Options
jsonMediaTypeFormatter.Options = value

Gets or sets the JSON serializer options.

Методы

DeserializeAsync``1
public Task<T> DeserializeAsync<T>(HttpContent content, CancellationToken cancellationToken)
result = jsonMediaTypeFormatter.DeserializeAsync(content, cancellationToken)

Deserializes the HTTP content into an instance of .

content
The HTTP content to deserialize.
cancellationToken
A cancellation token.

Возвращает: A task representing the deserialized value.

Serialize
public HttpContent Serialize(object value)
result = jsonMediaTypeFormatter.Serialize(value)

Serializes the specified value into HttpContent.

value
The value to serialize.

Возвращает: The serialized HTTP content.