Ageis
Ageis

Reputation: 2315

what is the difference between these two piece of json

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":"[email protected]","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": "[email protected]",
        "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))

Upvotes: 0

Views: 45

Answers (1)

Mohammad
Mohammad

Reputation: 2764

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 )

Upvotes: 1

Related Questions