NewtonsoftMediaTypeFormatter

Ecng.Net

A media type formatter for JSON content using Newtonsoft.Json.

Реализует: IMediaTypeFormatter

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

NewtonsoftMediaTypeFormatter
public NewtonsoftMediaTypeFormatter()
newtonsoftMediaTypeFormatter = NewtonsoftMediaTypeFormatter()

Initializes a new instance of the NewtonsoftMediaTypeFormatter class with default serializer settings.

NewtonsoftMediaTypeFormatter
public NewtonsoftMediaTypeFormatter(JsonSerializerSettings settings)
newtonsoftMediaTypeFormatter = NewtonsoftMediaTypeFormatter(settings)

Initializes a new instance of the NewtonsoftMediaTypeFormatter class with the specified serializer settings.

settings
The JSON serializer settings.

Свойства

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

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

Settings
public JsonSerializerSettings Settings { get; set; }
value = newtonsoftMediaTypeFormatter.Settings
newtonsoftMediaTypeFormatter.Settings = value

Gets or sets the JSON serializer settings.

Методы

DeserializeAsync``1
public Task<T> DeserializeAsync<T>(HttpContent content, CancellationToken cancellationToken)
result = newtonsoftMediaTypeFormatter.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 = newtonsoftMediaTypeFormatter.Serialize(value)

Serializes the specified value into HttpContent.

value
The value to serialize.

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