小编Ary*_*a11的帖子

如何在 .net web api 中将 DateTime 对象作为 json 传递

我有一个包含 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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我为这个类创建了一个控制器来通过 api 发送我的帖子请求。但我不知道如何将 DateTime 类型绑定到 json 我已经尝试了一个具有以下正文的请求,但没有成功:

    {"parentId":1,"note":"hello world","due":{"year":2017,"month": 11,"day":25}}
Run Code Online (Sandbox Code Playgroud)

我应该如何发布 DateTime 类型?

asp.net-web-api asp.net-core

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-core ×1

asp.net-web-api ×1