【问题标题】:Bind nested json object to Class将嵌套的 json 对象绑定到 Class
【发布时间】:2020-09-23 12:14:30
【问题描述】:

我正在尝试将具有此结构的 json 对象绑定到 ma 类 recItem:

"results": [
    {
        "id": "bjjiga1ee915r25f6vojrrbj5d",
        "name": "25026CE_r4_0-BR-WEB.pdf",
        "default": {
            "Date modified": "20200828114557000",                
            "Size": "18098154"
        }
    }
]

我成功绑定了根级别的所有项目,但如何绑定“修改日期”等属性?

这是我的两门课:

public class recItem
    {
        public string id { get; set; }            
        public string name { get; set; }    
        [JsonProperty("Date modified")]
        public string dateModified { get; set;}        
        
    }

public class recItemDefault
    {
        [JsonProperty("default")]
        public string dateModified { get; set; }
    }

【问题讨论】:

  • this answer,似乎对初学者很有帮助。
  • 它真的解决了我的问题,一切都说得通。谢谢@Sinatr

标签: c# json api


【解决方案1】:

一起试试这些课程:

public class Rootobject
{
public string id { get; set; }
public string name { get; set; }
public Default _default { get; set; }
}


public class Default
{
public string Datemodified { get; set; }
public string Size { get; set; }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    相关资源
    最近更新 更多