且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用未知对象名称反序列化 JSON

更新时间:2023-01-16 23:38:49

看起来你应该能够摆脱你的 Measures 类.相反,将字典直接放入您的 Body 类:

It looks like you should be able to just get rid of your Measures class. Instead, put the dictionary straight into your Body class:

public class Body
{
    public string _id { get; set; }
    public Place place { get; set; }
    public int mark { get; set; }
    public Dictionary<string, SingleModule> measures { get; set; }
    public string[] modules { get; set; }
}

另外,我强烈建议您的属性遵循 .NET 命名约定,并使用 [JsonProperty("measures")] 等向 Json.NET 指示如何翻译您的属性属性转换成 JSON.

As a separate matter, I'd strongly recommend following .NET naming conventions for your properties, and using [JsonProperty("measures")] etc to indicate to Json.NET how to translate your properties into JSON.