using Newtonsoft.Json;
namespace WebApi.Controllers
{
public class Rootobject
{
public string PhoneNumber { get; set; }
public string Name { get; set; }
public string MF { get; set; }
public string BirthDate { get; set; }
public object MaritalStatus { get; set; }
public object Country { get; set; }
}
[Route("api/[controller]/[action]")]
[ApiController]
public class ValuesController : ControllerBase
{
[HttpGet]
public IEnumerable<string> Get()
{
var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
var data = new Rootobject() {PhoneNumber="13800138000", Name="测试" };
var json = JsonConvert.SerializeObject(data, Formatting.Indented,jsonSetting);
return new string[] { json };
}
}
}
//结果: { "PhoneNumber": "13800138000", "Name": "测试" }