I need to retrieve the name of every product from an API to a listbox in C# (Visual Studio) and I've managed to login sucessfully into the API. I was able to retrieve the data of each product serialized but when I try to deserialize it the result for each product comes like this: 'app1.Form1+Data'. How can I retrieve the name of each product correctly?
Code:
public class Data
{
public int id { get; set; }
public string name { get; set; }
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 20; i++)
{
string url = reqlbl.Text;
WebClient c = new WebClient();
String userName = "user";
String passWord = "pass";
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + passWord));
c.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
var json = c.DownloadString(url + i.ToString());
Data result = JsonConvert.DeserializeObject<Data>(json);
listBox1.Items.Add(result);
}
}
Note: The variable 'i' represents a product. There are 20 products in total.
Here's an API example of product 1:
{"1":{"id":1,"name":"Product1"}}
{"Data":{"id":1,"name":"Product1"}}?Productthat has anint idandData itemas members, and then Deserialize toproductinstead ofData