我制作了一个 API,在实体框架详述之后,我发送了一个在 Json 中序列化的对象。
我的对象:
public class Package
{
public int Items { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public double? Weight { get; set; }
public string Size { get; set; }
public string PackageType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当收到它(Xamarin 应用程序)后,问题就开始了,Json 的第一个字母小写,但我想在完全相同的类中反序列化它,但不能,因为该类具有大写的属性(C# 标准)。现在我正在使用一个可怕的“助手”类,它具有小写的属性来翻译它。
知道如何处理这个问题并直接用大写首字母发送 Json 吗?
编辑
我使用ASP.NET Web API Core和Newtonsoft.Json
在 Xamarin 应用程序中,我使用System.Text.Json