0

Before we rewrote the system to use a wcf service the json returned to the client is :

{"CreationDate":"2016-12-01T13:15:02.923+00:00","Email":"sagysad@dd.com","IsApproved":true,"IsLockedOut":false,"IsOnline":true,"LastActivityDate":"2017-03-31T00:13:21.333+01:00","LastLockoutDate":"1754-01-01T00:00:00+00:00","LastLoginDate":"2017-03-31T00:13:21.113+01:00","LastPasswordChangedDate":"2099-12-31T00:00:00+00:00","ProviderName":"LoginProvider","ProviderUserKey":"dcc5f38f-f71e-4d9d-bdb2-58fb60b7a65e","UserName":"schoi","IsValidLogin":true}

but after exposing it as a wcf service the json has changed to this:

{
    "SignInResult":
    {
        "CreationDate": "/Date(1480598102923+0000)/",
        "Email": "steven.choi@dasdada.com",
        "IsApproved": true,
        "IsLockedOut": false,
        "IsOnline": true,
        "IsValidLogin": true,
        "LastActivityDate": "/Date(1490916050417+0100)/",
        "LastLockoutDate": "/Date(-6816268800000+0000)/",
        "LastLoginDate": "/Date(1490916050417+0100)/",
        "LastPasswordChangedDate": "/Date(-2208988800000+0000)/",
        "ProviderName": "LoginProvider",
        "ProviderUserKey": "dcc5f38f-f71e-4d9d-bdb2-58fb60b7a65e",
        "UserName": "schoi"
    }
}

why can't I just do this

JsonConvert.DeserializeObject<SignInResult>((provider.SignIn(username,password))
Ageis
  • 2,221
  • 4
  • 22
  • 34
  • See: http://stackoverflow.com/questions/206384/how-do-i-format-a-microsoft-json-date?noredirect=1&lq=1 – jmunsch Mar 30 '17 at 23:28

1 Answers1

1

According to this msdn link, DateTime objects are:

...represented in JSON as "/Date(number of ticks)/". The number of ticks is a positive or negative long value that indicates the number of ticks (milliseconds) that have elapsed since midnight 01 January, 1970 UTC.

if you want deserilze it with newsoft you can use this:

        JsonSerializerSettings settings = new JsonSerializerSettings
        {
            DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
            Formatting = Formatting.Indented
        };
JsonConvert.DeserializeObject<SignInResult>((provider.SignIn(username,password), settings )
Mohammad
  • 2,724
  • 6
  • 29
  • 55