I have a problem with JSON that is downloading from bank api. I am making some sort of ATM.
private void get_response()
{
WebClient wp = new WebClient();
string url = "http://api.nbp.pl/api/exchangerates/tables/a/?format=json";
var response = wp.DownloadString(url);
var jsonData = System.Text.Json.JsonSerializer.Deserialize<List<Rootobject>>(response);
Console.WriteLine(jsonData[0].rates.ToString());//ATM.Rates+Rate[]
Console.WriteLine(jsonData[0].rates[1].currency.ToString());//USD Dolar
get_data(response);
}
I was searching a lot and I didn't find answer to my problem. Only that I need to use List but I have no idea how to use it and make it again to json but only that rates table. My Class:
public class Rootobject
{
public Class1[] Property1 { get; set; }
}
public class Class1
{
public string table { get; set; }
public string no { get; set; }
public string effectiveDate { get; set; }
public Rate[] rates { get; set; }
}
public class Rate
{
public string currency { get; set; }
public string code { get; set; }
public float mid { get; set; }
}
I need to display Rate table in my App but I have no idea how to get into rates value in JSON string because when i display response this happen.
private void get_data(string response)
{
dataGridView.Rows.Clear();
DataTable dataTable = (DataTable)JsonConvert.DeserializeObject(response, (typeof(DataTable)));
dataGridView.DataSource = dataTable;
}