gpt4 book ai didi

c# - JSON 值无法转换为 System.DateTime

转载 作者:行者123 更新时间:2023-12-03 09:46:39 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





JSON Date and DateTime serialisation in c# & newtonsoft

(4 个回答)


去年关闭。




我有一个 员工 table

public class Employee
{
[Key]
public long ID { get; set; }
public DateTime EmpDate { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}

我创建了 Web API 来发布员工数据:
[HttpPost]
public async Task<ActionResult<Employee>> PostLead(Employee employee)
{
//Code to post
}

这是我的 JSON 正文
{
"firstname":"xyz",
"lastname":"abc",
"EmpDate":"2019-01-06 17:16:40"
}

我收到的错误是 The JSON value could not be converted to System.DateTime.但是当我通过 招聘日期 值为 2019-01-06 ,我没有收到错误消息。

最佳答案

您的 JSON 中的日期值不正确。应该

2019-01-06T17:16:40

大多数解析器使用 ISO 8601

关于c# - JSON 值无法转换为 System.DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59866943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com