저는 C #을 처음 사용합니다. 콘솔 날씨 앱을 만들려고합니다. OpenWeather API에서 다음과 같은 JSON 데이터를 가져 왔습니다.
"coord": {
"lon": 27.5667,
"lat": 53.9
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
나는 전화했다 JsonConvert.DeserializeObject<WeatherInfo>(stringResult);
coord
부품 을 역 직렬화 할 수 있지만 weather
부품이 배열 인 경우 어떻게 역 직렬화합니까?
private class WeatherInfo
{
public Coord Coord { get; set; }
public Weather Weather { get; set; }
}
private class Weather
{
public readonly string Id;
public readonly string Main;
public readonly string Description;
public readonly string Icon;
public Weather(string lat, string lon, string id, string main, string description, string icon)
{
Id = id;
Main = main;
Description = description;
Icon = icon;
}
}
private class Coord
{
public readonly string Lat;
public readonly string Lon;
public Coord(string lat, string lon)
{
Lat = lat;
Lon = lon;
}
}
```
public Weather[] Weather { get; set; }
매핑에 사용 합니다. JSON에 해당하는 C # 개체는 다음과 같습니다.
public partial class Temperatures
{
[JsonProperty("coord")]
public Coord Coord { get; set; }
[JsonProperty("weather")]
public Weather[] Weather { get; set; }
}
public partial class Coord
{
[JsonProperty("lon")]
public double Lon { get; set; }
[JsonProperty("lat")]
public double Lat { get; set; }
}
public partial class Weather
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("main")]
public string Main { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("icon")]
public string Icon { get; set; }
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다