- class API
- {
-
- }
-
- public class RootObject
- {
- public int customerid { get; set; }
- public string name { get; set; }
- public string email { get; set; }
- public DateTime reference { get; set; }
- public int status { get; set; }
- public DateTime dateupdated { get; set; }
- }
I need to populate combo box customer_cb with "name". I use DataContractJsonSerializer
- WebClient client = new WebClient();
- string json = client.DownloadString(url);
- using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
- {
- DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(RootObject));
- RootObject obj = (RootObject)deserializer.ReadObject(ms);
-
-
- foreach(var name in obj.name)
- {
- ComboboxItem item = new ComboboxItem();
- item.Text = name.ToString();
- customer_cb.Items.Add(item);
- }
- }
When I run the application I get error
- Object Reference not set to an instance of an object
Please help.