1

I am using the solution in the follow SO post (Deserializing dates with dd/mm/yyyy format using Json.Net), but am getting the following error when trying to Deserialize MyObject:

String was not recognized as a valid DateTime.

Any help would be appreciated.

class Program
{
    static void Main(string[] args)
    {
        var json = "{\"data\":[{\"courseID\":43547,\"endDate\":\"01/01/2014\"},{\"courseID\":40949,\"endDate\":\"10/04/2013\"},{\"courseID\":40439,\"endDate\":\"7/03/2013\"}]}";

        var myCheckedCourses = JsonConvert.DeserializeObject<MyObject>(json, 
            new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" });

    }
}

class MyObject
{
    public List<Object2> data { get; set; }
}

[JsonObject]
public class Object2
{
    public int CourseID { get; set; }
    public Nullable<System.DateTime> EndDate { get; set; }
}
2
  • 2
    7/03/2013 isn't in dd/MM/yyyy format. Commented May 20, 2014 at 15:51
  • Hi @AllanHorwitz I suggest you that date field in json should be in UTC Format. And it will good for you and server too. Commented May 20, 2014 at 15:59

1 Answer 1

1

The date format needed to be changed to d/MM/yyyy.

Sign up to request clarification or add additional context in comments.

1 Comment

In my opinion, this is not the right answer. Does that really work for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.