views:

214

answers:

1

HI! 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 string. So I cant mark this 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

A: 

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

axel_c