In Postman, I'm sending the following JSON via a POST to API.
{
"id": "21",
"crgName": "Walgreens - 11/07/2018 - Standard ",
"crgStarteddatetime": "2018-11-07T10:11:10",
}
...but, I get the following error: FormatException: String was not recognized as a valid DateTime.
Inside my controller, I'm using DateTimeFormat to format the date time:
public static RemoteContextType DeserializeJsonString<RemoteContextType>(string jsonString)
{
//create an instance of generic type object
RemoteContextType obj = Activator.CreateInstance<RemoteContextType>();
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));
var serializer = new DataContractJsonSerializer(obj.GetType(),
new DataContractJsonSerializerSettings
{
DateTimeFormat = new
DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss.fff'Z'")
});
obj = (RemoteContextType)serializer.ReadObject(ms);
ms.Close();
return obj;
}
...is there an issue in my syntax as to how I have the Date formatted? My intentions are to formate the date as it is reflected in the JSON. Could I get some help as to what am I doing wrong?