相关疑难解决方法(0)

System.Text.Json.Serialization 似乎不适用于具有嵌套类的 JSON

如何定义仅使用 System.Text.Json.Serialization 工作的类?

使用 Microsoft 的 Newtonsoft 反序列化新替代方案目前不适用于嵌套类,因为在反序列化 JSON 文件时,所有属性都设置为 null。使用 Newtosonsoft 的 Json property 属性[JsonProperty("Property1")]来维护属性的值。

谢谢!

public class Class1
{
    [JsonProperty("Property1")]
    public string Property1 { get; set; }
}
    
Run Code Online (Sandbox Code Playgroud)

使用 Visual Studio 的粘贴 JSON 到类进行粘贴以创建类:

public class Rootobject
{
    public string Database { get; set; }
    public Configuration Configuration { get; set; }
}

public class Configuration
{
    public Class1 Class1 { get; set; }
    public Class2 Class2 { get; set; }
    public Class3 Class3 { get; …
Run Code Online (Sandbox Code Playgroud)

c# json .net-5 system.text.json blazor-webassembly

5
推荐指数
1
解决办法
2861
查看次数

标签 统计

.net-5 ×1

blazor-webassembly ×1

c# ×1

json ×1

system.text.json ×1