gpt4 book ai didi

c# - 使用嵌套对象中的属性反序列化 JSON

转载 作者:太空狗 更新时间:2023-10-29 21:32:57 24 4
gpt4 key购买 nike

<分区>

如何轻松地将此 JSON 反序列化为 OrderDto C# 类?有没有办法以某种方式使用属性来做到这一点?

JSON:

{
"ExternalId": "123",
"Customer": {
"Name": "John Smith"
}
...
}

C#:

public class OrderDto
{
public string ExternalId { get; set; }
public string CustomerName { get; set; }
...
}

我尝试使用 JsonProperty 属性,但没能成功。我的想法是编写如下注释:

[JsonProperty("Customer/Name")]
public string CustomerName { get; set; }

但这似乎行不通。有任何想法吗?谢谢! :)

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com