JSON值无法转换为System.DateTime [英] The JSON value could not be converted to System.DateTime

查看:1423
本文介绍了JSON值无法转换为System.DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Employee

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来发布员工数据:

I have created web API to post the employee data:

[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.的错误,但是当我将 EmpDate 值作为2019-01-06传递时,我没有收到错误.

I am getting error as The JSON value could not be converted to System.DateTime. But when I pass EmpDate value as 2019-01-06, I am not getting an error.

推荐答案

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

your date value in your JSON isn't correct. should be

2019-01-06T17:16:40

大多数解析器使用 ISO 8601

这篇关于JSON值无法转换为System.DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆