【发布时间】:2022-01-28 17:03:34
【问题描述】:
builder.Services.AddControllers().AddXmlSerializerFormatters(); //I added xml
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
public class WeatherForecastList //Class I want to post in xml
{
public List<WeatherForecast> Forecasts { get; set; }
}
[HttpPost] //Experimental method
public ActionResult<WeatherForecastList> GetWeather([FromBodyAttribute]
WeatherForecastList WeatherForecast)
{
return Ok(WeatherForecast);
}
<WeatherForecastList>
<Forecasts>
<WeatherForecast>
.
.
</WeatherForecast>
</Forecasts
</WeatherForecastList>
我目前正在尝试在 dotnet 6 中使用 XML 而不是 JSON 来发布帖子。如果我只发布一个简单的对象,我就可以让它工作。我想了解如何使用嵌套和其他类型的列表发布更复杂的类型。目标是获取 xml 然后返回它。我希望 xml 的结构看起来像上面一样。
【问题讨论】:
标签: c# asp.net-core .net-core asp.net-core-webapi