I'm new to JSON and I'm retrieving the following structure from an API call...
{
"Customers":[
{
"Code":"11111",
"Alpha":"A",
"Name":"Test A",
"Address":{
"Contact":"John Doe",
"Address1":"PO Box 111",
"Address2":"",
"Address3":"",
"City":"DE PERE",
"Postcode":"54115",
"State":"WI",
"Country":"USA"
}
},
{
"Code":"22222",
"Alpha":"B",
"Name":"Test B",
"Address":{
"Contact":"Jane Doe",
"Address1":"PO Box 222",
"Address2":"",
"Address3":"",
"City":"DE PERE",
"Postcode":"54115",
"State":"WI",
"Country":"USA"
}
}
]
}
I'm able to parse the 'Customers' data with the following...
public class Customer
{
public string Code { get; set; }
public string Name { get; set; }
}
public class CustomerList
{
public List<Customer> Customers { get; set; }
}
dynamic jObj = JsonConvert.DeserializeObject(json);
dynamic jsonObj = JsonConvert.DeserializeObject<CustomerList>(json);
foreach (var obj in jsonObj.Customers)
{
string Name = obj.Name;
string Code = obj.Code;
}
But I'm having a heck of a time getting into the 'Address' data. I tried a few things I saw in some other posts, to no avail. Any help would be appreciated.
Thanks