【发布时间】:2020-01-10 11:33:12
【问题描述】:
我使用 ASP.NET Core 2.2 创建了一些 web-api,它们返回 JSON 响应。
但是,在我的本地调试中,当我拨打电话时,一切似乎都正常,但是当我在我的 JSON 响应中继续在 Azure 上发布时,我在播种过程中插入的每个 \n 之后都会看到额外的空格。
所以对于同一个请求,我有这个本地响应:
{"id":57,"content":"First Line. \nSecond Line.\nThird Line","otherAttrubute":"otherValue"}
还有这个实时(或远程,如果你喜欢)版本:
{"id":57,"content":"First Line. \r\n Second Line.\r\n Third Line","otherAttrubute":"otherValue"}
我在DbContext 的OnModelCreating 中播种我的数据库:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var myObjects = new MyObject[]
{
[previous objects],
new MyObject { Id=57, Content "First Line. \nSecond Line.\nThird Line", OtherAttrubute="otherValue" },
[following objects]
};
modelBuilder.Entity<MyObject>().HasData(myObjects);
base.OnModelCreating(modelBuilder);
}
在我的控制器中,我还尝试在Content 属性上使用Trim(),然后用return Ok(myObject) 返回我的对象,但它不起作用。
我的猜测是这种行为可能是由 Azure SQL 数据库引起的,但我不确定。
如果您需要查看更多代码,请询问。 谢谢
【问题讨论】:
标签: entity-framework azure azure-sql-database asp.net-core-webapi