I am pulling weather data from a Web API call which returns JSON which populates the following class:
public class WeatherResponse
{
public string queryCost { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string resolvedAddress { get; set; }
public string address { get; set; }
public string timezone { get; set; }
public string tzoffset { get; set; }
public List days { get; set; }
}
There is a List inside it: DayInfo with the daily info for a number of days (see below).
public class DayInfo
{
public string datetime { get; set; }
public string tempmax { get; set; }
public string tempmin { get; set; }
// etc..
}
How do I iterate through this list in the WeatherResponse object. eg: with a foreach.
Basically I need to insert the data for each day into an MS SQL table.
Thanks.
Aman GuptaPosted Sep 7, 2024, 9:35 AM
Hi Tony,
To iterate through the List inside the WeatherResponse object and insert the data for each day into an MS SQL table, you can use a foreach loop. Here's a general outline of how to achieve this, including the SQL insertion logic:
You can use this process.
Make sure to modify the connection string and table name according to your setup.
Uday DodiyaPosted Sep 7, 2024, 9:05 AM
Hi, Tony B,
Try Following