JsonMediaTypeFormatter
Ecng.Net
A media type formatter for JSON content using System.Text.Json.
Implementiert: IMediaTypeFormatter
Konstruktoren
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.
Eigenschaften
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.
Methoden
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.
Rückgabe: 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.
Rückgabe: The serialized HTTP content.