This is a follow up to a question that I asked before. I am trying to parse an array of JSON data. I have the following classes for the data. I have the data in a list and I can loop through the RootObject data but I am having trouble looping the the child StoreDepartment data. Can someone tell me how I can accomplish this? Thank you.
string sJSON = @"[{""dateNumeric"":1216000000,""hourOfDay"":0,""customerNumber"":12,""storedepartment"":[{""department"":333,""descriptionOfDepartment"":""Department A""},{""department"":111,""descriptionOfDepartment"":""Department B""}]},{""dateNumeric"":1216000000,""hourOfDay"":3,""customerNumber"":3,""storedepartment"":[{""department"":999,""descriptionOfDepartment"":""Department X""},{""department"":888,""descriptionOfDepartment"":""Department Y""}]}]";
List<RootObject> Data = JsonConvert.DeserializeObject<List<RootObject>>(sJSON);
foreach (RootObject c in Data)
{
debugOutput(c.dateNumeric.ToString());
debugOutput(c.customerNumber.ToString());
}
public class RootObject
{
public int dateNumeric { get; set; }
public int hourOfDay { get; set; }
public int customerNumber { get; set; }
public List<Storedepartment> storedepartment { get; set; }
}
public class Storedepartment
{
public int department { get; set; }
public string descriptionOfDepartment { get; set; }
}
StoreDepartmant, and what kind of a trouble you are having? Are you having an exception?c.storedepartmentshould be the list that you want to iterate, however you might just want to make sure it isn'tnullbefore going over it