如何在.net Web API中将DateTime对象作为json传递

Arya11

我有一个其中有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;
        }
    }

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

    {"parentId":1,"note":"hello world","due":{"year":2017,"month": 11,"day":25}}

我应该如何发布DateTime类型?

Arya11

显然,您可以执行以下操作之一:

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

这实际上是一个简单的问题,但是如果您要确保如何对未知对象类型格式进行适当的后期处理,则最好发送带有空主体的对象以查看默认值。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在WEB API中将多个模型作为参数传递

如何在ASP.NET Web API上获取对象?

如何在Asp.net Core Web Api中将Newtonsoft.Json用作默认值?

如何在ASP.NET Web API中接收JSON?

如何在ASP.NET Framework Web API中返回自定义JSON对象?

如何在Nginx服务器中将ASP.NET Core Web API dll文件作为服务运行?

如何在.NET Web API中使用Unity进行解析

如何在.net Core Web API中构造数据验证?

如何在Net Core Web API中覆盖OnAuthorization?

如何在.Net Web API中使用BSON

如何在.NET Core Web API中配置并发?

如何在 .net core web 中使用 Json() 函数?

如何将JSON POST数据作为对象传递给Web API方法?

如何在.NET Web API应用程序中将FluentValidation与Swagger一起使用?

如何在 .net core web api 中将 FromRoute 绑定到 QueryObject?

如何在ASP.Net中将Web服务层添加到Web应用程序

如何在.net core 2.2 Web API中传递带有“禁止”响应的字符串

如何在 Web api c# 中将 List<> 作为 Json 返回

如何从.Net Core Web API返回Json?

如何在Web API(ASP.NET Core-> Web API)上发布SOAP消息

如何在Scala中将任何对象作为Json Writeable传递?

如何在WSK(Openwhisk)中将JSON对象作为参数传递

如何在获取请求中将 json 对象作为查询传递

如何在C#.NET Web API中接收和拆分对象数组

如何在ASP.NET Core Web API中发布对象列表

如何在asp.net web api中获取模型包含文本json属性的json数据?

如何在.Net Web API中包含System.Web.Http.Cors参考dll

如何在 .Net 5 Web API 项目启动时不打开 Web 浏览器

我如何在 asp.net web api 项目而不是 .net core 上使用 DI