R – How to deserialize elementary types from json in ASP.NET(System.Runtime.Serialization.Json)

asp.netjsonjsonserializer

I have a little problem.
When I'm using DataContractJsonSerializer with complex types(own types) it works fine. But I have to deserialize TimeStamp or DateTime from a string. So I cant mark these types with DataContract, DataMember attributes.

I wrote some code

string jsonedTS = "PT2M15S";

DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(TimeSpan));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonedTS));
try {
    result.Takes = (TimeSpan) jsonSerializer.ReadObject(ms);
} catch {
 ;
}

And I catch this Exception

{"There was an error deserializing the object of type System.TimeSpan. Encountered unexpected character 'P'."} System.Exception {System.Runtime.Serialization.SerializationException}

And My Question IS
How Can I deserialize

Best Answer

You can try with Json.Net library - it's worked pretty well for us in the past.