class Program
{
public static void Main()
{
var client = new RestClient();
var request = new RestRequest(url);
var response = client.Get(request);
var weatherResponse = JsonSerializer.Deserialize<Root>(response.Content);
Console.WriteLine(Resp.current.temp_c);
foreach(var e in Resp.forecast.forecastDay)
{
Console.WriteLine(e.day.daily_chance_of_rain);
}
}
}
public class Root
{
public Forecast forecast { get; set; }
public Current current { get; set; }
public double wind_kph { get; set; }
public string wind_dir { get; set; }
public double pressure_mb { get; set; }
public double uv { get; set; }
}
public class Current
{
public double temp_c { get; set; }
}
public class Forecast
{
public List<ForecastDay> forecastDay { get; set; }
}
public class ForecastDay
{
public Day day { get; set; }
public Astro astro { get; set; }
}
public class Day
{
public double daily_chance_of_rain { get; set; }
}
public class Astro
{
public string sunrise { get; set; }
public string sunset { get; set; }
}
Forecast.forecastDay.get вернул null. При выполнении выдает ошибку. Пытался к gpt обращаться, лучше не стало. Пример Json
{
"current": {
"last_updated_epoch": 1680967800,
"last_updated": "2023-04-08 16:30",
"temp_c": 15.0,
"temp_f": 59.0,
"is_day": 1,
"condition": {
"text": "Sunny",
"icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
"code": 1000
},
"wind_mph": 9.4,
"wind_kph": 15.1,
"wind_degree": 70,
"wind_dir": "ENE",
"pressure_mb": 1025.0,
"pressure_in": 30.27,
"precip_mm": 0.0,
"precip_in": 0.0,
"humidity": 41,
"cloud": 0,
"feelslike_c": 14.5,
"feelslike_f": 58.1,
"vis_km": 10.0,
"vis_miles": 6.0,
"uv": 4.0,
"gust_mph": 7.8,
"gust_kph": 12.6
},
"forecast": {
"forecastday": [
{
"date": "2023-04-08",
"date_epoch": 1680912000,
"day": {
"maxtemp_c": 14.6,
"maxtemp_f": 58.3,
"mintemp_c": 5.4,
"mintemp_f": 41.7,
"avgtemp_c": 9.9,
"avgtemp_f": 49.8,
"maxwind_mph": 6.9,
"maxwind_kph": 11.2,
"totalprecip_mm": 0.0,
"totalprecip_in": 0.0,
"totalsnow_cm": 0.0,
"avgvis_km": 10.0,
"avgvis_miles": 6.0,
"avghumidity": 70.0,
"daily_will_it_rain": 0,
"daily_chance_of_rain": 0,
"daily_will_it_snow": 0,
"daily_chance_of_snow": 0,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
"code": 1003
},
"uv": 3.0
},
"astro": {
"sunrise": "06:21 AM",
"sunset": "07:45 PM",
"moonrise": "10:56 PM",
"moonset": "07:08 AM",
"moon_phase": "Waning Gibbous",
"moon_illumination": "96",
"is_moon_up": 1,
"is_sun_up": 0
}
}
]
}
Мог в json со скобками накосячить