JsonConvert.DeserializeObject could not convert string to DateTime when using non-us date formats

后端 未结 1 1624
臣服心动
臣服心动 2020-12-15 16:17

I have the following serialized json object:

\"{\\\"LineItems\\\":[{\\\"LineID\\\":1,\\\"QuoteID\\\":\\\"00000000-0000-0000-0000-000000000000\\\",\\\"Quantit         


        
相关标签:
1条回答
  • 2020-12-15 16:40

    Try specifying the DateTime format specifically using an IsoDateTimeConverter, and pass it into the JsonConvert.DeserializeObject<>() method.

    ...
    var json = Request.RequestContext.HttpContext.Request.Params["EoiDraftModel"];
    
    var format = "dd/MM/yyyy"; // your datetime format
    var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = format };
    
    var ld = JsonConvert.DeserializeObject<EoiDraftViewModel>(json, dateTimeConverter);
    ...
    
    0 讨论(0)
提交回复
热议问题