using System.Text;
using System.Text.Json;
namespace System.Net.Http
{
///
/// JsonContent,預設application/json,使用System.Text.Json效能最佳化
///
public class JsonContent : StringContent
{
#region Fields
private const string JsonContentType = "application/json";
#endregion Fields
#region Constructors
///
/// Initializes a new instance of the System.Net.Http.JsonContent class
/// with default settings.
///
/// The content to used to initialize the instance.
public JsonContent(object content) : base(JsonSerializer.Serialize(content), Encoding.UTF8, JsonContentType)
{
}
///
/// Initializes a new instance of the System.Net.Http.JsonContent class
/// with given serialization settings.
///
/// The content to used to initialize the instance.
/// The settings to used to serialize the content.
public JsonContent(object content, JsonSerializerOptions settings) : base(JsonSerializer.Serialize(content, settings), Encoding.UTF8, JsonContentType)
{
}
///
/// Initializes a new instance of the System.Net.Http.JsonContent class
/// with given json content and default settings.
///
/// The json content to used to initialize the instance.
public JsonContent(string json) : base(json, Encoding.UTF8, JsonContentType)
{
}
///
/// Initializes a new instance of the System.Net.Http.JsonContent class
/// with given parameters.
///
/// The json content to used to initialize the instance.
/// The encoding to used to encode the content.
public JsonContent(string json, Encoding encoding) : base(json, encoding, JsonContentType)
{
}
#endregion Constructors
}
}