asp.net-mvcjsonjson-spirit

.Net's Json Date & C++ Client


I have an MVC project that provides (GET) & consumes (PUT) a Json object. The JsonValueProviderFactory automatically binds the Json object to the model object.

One of the property in the object is DateOfBirth of type DateTime.

When I do a GET, the following Json result is produced:

{
"DateOfBirth" : "/Date(1285093800000)/"
}

But when I send (PUT) the same to the server, the value is not bound to the Model object. DateOfBirth always DateTime.MinValue. Other properties of the same object are bound correctly. The problem is only with DateTime.

I am using json_spirit on the client (C++). I have tried sending "\/Date(1285093800000)\/" via json_spirit but still doesn't work.

Please help.


Solution

  • The problem was that json_spirit converted \/Date(1285093800000)\/ to \\/Date(1285093800000)\\/. It did not escape / (forward slashes).

    So I modified json_spirit to escape even / (forward slashes). Now when I pass /Date(1285093800000)/ it correctly converts it to \/Date(1285093800000)\/. This is what .Net's json serializer expects.

    Thanks.