我有一个模型,其中包含 DateTime 类型:

    public class ToDo 
    { 
        public int id { get; set; } 
        public int parentId { get; set; } 
        public string note { get; set; } 
        public DateTime due { get; set; } 
        public ToDo(int id, int parentId, string note, DateTime due) 
        { 
            this.id = id; 
            this.parentId = parentId; 
            this.note = note; 
            this.due = due; 
        } 
    } 

我已经为这个类创建了一个 Controller 来通过 api 发送我的 post 请求。但我不知道如何将 DateTime 类型绑定(bind)到 json 我尝试了一个带有以下正文的请求,但没有成功:
    {"parentId":1,"note":"hello world","due":{"year":2017,"month": 11,"day":25}} 

我应该如何发布 DateTime 类型?

请您参考如下方法:

显然,您可以这样做的一种方法是:

{"due": "2017-11-01T00:00:00"} 

这实际上是一个简单的问题,但如果您想确定如何为未知对象类型格式发出正确的发布请求,最好发送一个带有空主体的对象以查看默认值。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!