NewtonsoftMediaTypeFormatter
Ecng.Net
A media type formatter for JSON content using Newtonsoft.Json.
构造函数
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.