Sunday, 15 August 2010

c# - Error when DeserializeObject to Datetime -


I'm trying to convert Dettaim a JSON string faced by the date of the headers and an error .

My code:.

  if (actionContext.Request.Headers.Contains ( "DataSync")) {var date = actionContext.Request.Headers.GetValues ​​( "DataSync") before (); UserRequest.LastSync = JsonConvert.DeserializeObject & lt; DateTime & gt; (Date, new ISDATEContent ()); }  

Error:

  "Message": "An error has occurred." "ExceptionMessage": "token unexpected error on reading :. integer. Paths, line 1, position 2.", "ExceptionType": "Newtonsoft.Json.JsonReaderException", "StackTrace": "Newtonsoft.Json.JsonReader them. ReadAsDateTimeInternal () \ \ Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType (JsonReader Reader, Jason Contract Contract is a converter of Boolean) \ \ Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (JsonReader Reader, Type Object Type, Boolean Check Extra Content ) \ \ Em Newtonsoft.Json.JsonSerializer.DeserializeInternal (JsonReader Reader, type object type) \ \ Em Newtonsoft.Json.JsonConvert.DeserializeObject (String Value, type, JsonSerializer setting settings) \ \ em Newtonsoft.Json.JsonConvert.DeserializeObject [T] (string value, JsonSerializer setting settings) \ \ Em Portal.InfraStructure.Filters. UserRequestFilter .On Action Expanding (HTTPActionContact ActionCorrect xt) na: \\ Projetos \ API \ Portal \\ Infraestructure \\ Filter \\ UserRequestFilter.cs: Linha 28 \ SystemWeb.Http.Filters.ActionFilterAttribute.OnActionExecutingAsync (HttpActionContext actionContext, CancellationToken cancellationToken) \ \ --- local Fim rastreamento D pilha the anterior onde a exceção F E gerada --- \ \ them SystemkRuntimekCompilerServiceskTaskAwaiterkThrowForNonSuccess (Task task) \ \ System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification them (Task task) \ \ System.Web.Http.Filters.ActionFilterAttribute them. & Lt; ExecuteActionFilterAsyncCore & gt; D__0.MoveNext () \ \ --- Fim do rastreamento de pilha local anterior onde an exceção foie gerada --- \ \ make them from the system. Runtime Complementary Services. TaskAwaiter.ThrowForNonSuccess (Task Task) \ \ em System.Runtime Completer Services. TaskAwaiter.HandleNonSuccessAndDebugger Notification (Task Task) \ \ em System.Rentime Completer Services. TaskAwaiter`1.GetResult () \ \ em Systems Web. Http.Controllers.ActionFilterResult. & Lt; Executive EAsync & gt; D__2.MoveNext () \ \ ---FIFHST DOSTSTUSTERMATA DE PILO DOE LOCAL ANTIER ON EXCESIO FOE GERDA --- \ \ em system Runtime COMPLETER SERVICES Task aviator Trey Forenon Success (Task Task) \ \ em System Runtime .CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Work) \ \ em Sistmkrntiimkkanplrsrhwars. The commentator `1.GetResult () \ \ em System.Web.Http.Dispatcher.HttpControllerDispatcher. & Lt; SendAsync & gt; D__1.MoveNext ()  

I am using the postman for testing. I am calling my controller and passing the date in the header on the postman. Enter image details here What can I do to fix this error?

Resolution:

Use Date time.ps ()


No comments:

Post a Comment