Kzr*_*tof 7 c# json.net asp.net-core azure-functions system.text.json
我有一组在 .NET Core 3.1 上运行的 Azure Functions v3。
我需要指定自定义转换器,因此当我在函数中构建 a 时,System.Text.Json
我提供了一个自定义实例:JsonSerializerOptions
JsonResult
return new JsonResult(<ContractClass>, NSJsonSerializerOptions.Default)
{
StatusCode = StatusCodes.Status200OK
};
Run Code Online (Sandbox Code Playgroud)
问题
我收到以下错误,并且我不确定 Newtonsoft 来自哪里,因为 ASP.NET Core 应该使用System.Text.Json
:
Microsoft.AspNetCore.Mvc.NewtonsoftJson: Property 'JsonResult.SerializerSettings' must be an instance of type 'Newtonsoft.Json.JsonSerializerSettings'.
Run Code Online (Sandbox Code Playgroud)
更新
我发现该JsonResult
实例正在寻找 的实现IActionResultExecutor<JsonResult>
,并得到一个NewtonsoftJsonresultExecutor
而不是SystemTextJsonResultExecutor
。JsonResult
这是的方法的代码ExecuteResultAsync
:
我认为 Azure Function 将依赖于 ASP.Net Core,而 ASP.Net Core 又依赖于System.Text.Json
.
小智 -2
您的序列化项目必须继承自JsonSerializerSettings
:
new { Testc = "test" },
new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true,
//ContractResolver = new CamelCasePropertyNamesContractResolver(),
//ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4755 次 |
最近记录: |