I'm currently using the DataContractJsonSerializer
class but I cannot convert dates like 12/19/2013 12:00:00 AM
to a C# DateTime
Object.
The error that I'm getting says:
There was an error deserializing the object of type Uptivity.achievement. DateTime content '12/19/2013 12:00:00 AM' does not start with 'Date(' and end with ')' as required for JSON.
in:
public static T DeserializeJSon<T>(string jsonString)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T)ser.ReadObject(stream);
return obj;
}
I've been trying to define the datetime format like this:
public static T DeserializeJSon<T>(string jsonString)
{
var settings = new DataContractJsonSerializerSettings
{
DateTimeFormat = new System.Runtime.Serialization.DateTimeFormat("G")
};
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T),settings);
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T)ser.ReadObject(stream);
return obj;
}
But now I'm receiving:
There was an error deserializing the object of type Uptivity.achievement. String was not recognized as a valid DateTime.
Also this 12/19/2013 12:00:00 AM
format like Date is the one that the json provider is delivering.
Any ideas?