我有一个其中有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类型?
显然,您可以执行以下操作之一:
{"due": "2017-11-01T00:00:00"}
这实际上是一个简单的问题,但是如果您要确保如何对未知对象类型格式进行适当的后期处理,则最好发送带有空主体的对象以查看默认值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句