I've a valid JSON object that has a JSON array in it. The JSON array doesn't have curly braces and contains a comma separated list of mixed type in it. It looks like this:
{
"ID": 17,
"Days": 979,
"Start_Date": "10/13/2012",
"End_Date": "11/12/2012",
"State": "",
"Page": 1,
"Test": "Valid",
"ROWS": [
[441210, "A", "12/31/2009", "OK", "Done", "KELLEY and Co'", "12/31/2009", "06/29/2010", "TEXAS", "Lawyers", 6, "", "<img src=\"/includes/images/Icon_done.gif\" border=\"0\" alt=\"Done\" title=\"Done\" />"],
[441151, "B", "12/31/2009", "No", "In-process", "Sage & Co", "12/31/2009", "06/29/2010", "CALIFORNIA", "Realtor", 6, "", "<img src=\"/includes/images/Icon_InProcess.gif\" border=\"0\" alt=\"In Process\" title=\"In Process\" />"]
]
}
I've created a class to reflect the JSON structure, having a List for the complex array:
class myModel
{
public int ID { get; set; }
public int Days { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string State { get; set; }
public string Page { get; set; }
public string Test { get; set; }
List<ChildModel> Rows { get; set; }
}
I've tested it with a List of a List too:
List<List<ChildModel>> Rows { get; set; }
And the child model like this:
class ChildModel
{
public int ID { get; set; }
public string StatusId { get; set; }
public DateTime ContactDate { get; set; }
public string State { get; set; }
public string Status { get; set; }
public string CustomerName { get; set; }
public DateTime WorkStartDate { get; set; }
public DateTime WorkEndDate { get; set; }
public string Territory { get; set; }
public string CustType { get; set; }
public int JobOrder { get; set; }
public string Filler { get; set; }
public string Link { get; set; }
}
In my program.cs file, I'm deserializing it like this:
using (StreamReader r = new StreamReader(@"D:\01.json"))
{
myModel items = JsonConvert.DeserializeObject<myModel>(r.ReadToEnd());
}
When I run this program, the child object (Rows) is always null
. What am I doing wrong?