【发布时间】:2020-06-10 07:10:08
【问题描述】:
我有一个包含字段的文档:
{
FOB: "..."
}
但是当我退货时:
[HttpGet("{documentRef}")]
public ActionResult<Ten> Get(string documentRef)
{
var data = _service.FindOneTen(documentRef);
if (data != null) return data;
Response.StatusCode = 400;
return NotFound();
}
转换成这样:
{
fob: "..."
}
我怎样才能阻止这种情况发生/为什么会发生这种情况?
我见过人们使用的例子
PropertyNamingPolicy = null;
为 MVC/我尝试但没有工作的普通 JSON 禁用它。
启动:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddNewtonsoftJson();
}
编辑
虽然Objects exposed on JSON web-api - how to stop the property names changing case? 以一种方式解决问题,但我宁愿不需要为模型中的每个字段指定。
【问题讨论】:
-
“我有一份文件” - 什么样的“文件”? MongoDB?
Ten类是什么样的?阅读How to Ask 并提供所有相关详细信息。 -
您能指定,您想使用哪种约定?您想避免使用 camelCase 约定或使用您自己的约定名称
标签: c# asp.net-mvc-3 asp.net-web-api json.net