I'm trying to convert JSON to C# object using Json.NET. The object looks like this in C#:
public class MyObject
{
public int? integerValue {get;set;}
public DateTime? dateTimeValue {get;set;}
}
But when I run JsonConvert.DeserializeObject()
on the incoming JSON, I get the following Exception:
Unable to find a constructor to use for type System.Nullable`1[System.Int32]. A class should either have a default constructor or only one constructor with arguments.
--- EDIT ----
Well it turns out that after doing many tests, the problem boils down to that my input for my JSON was like this:
{integerValue:{}, dateTimeValue: {} }
instead of:
{integerValue: null, dateTimeValue: null}
It turns out that the {} is a valid way of representing a null object in JSON but the JSON.Net parser did not know to treat {} tokens the same way as 'null' when de-serializing.
Thanks everyone for your input!