Weather class
public class weatherdata
{
[DataMember]
public Weather weather { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
WEather api
{
coord: {
lon: -81.23,
lat: 42.98
},
sys: {
message: 0.0041,
country: "CA",
sunrise: 1427972655,
sunset: 1428018750
},
weather: [
{
id: 800,
main: "Clear",
description: "Sky is Clear",
icon: "01n"
}
],
base: "cmc stations",
main: {
temp: 276.227,
temp_min: 276.227,
temp_max: 276.227,
pressure: 1004.12,
sea_level: 1029,
grnd_level: 1004.12,
humidity: 80
},
wind: {
speed: 6.47,
deg: 198.502
},
clouds: {
all: 0
},
dt: 1427969795,
id: 6058560,
name: "London",
cod: 200
}
string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}", ErrorCode);
using (WebClient client = new WebClient())
{
string content = client.DownloadString(url);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(weatherdata));
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content)))
{
// deserialize the JSON object using the WeatherData type.
var weatherData = (weatherdata)serializer.ReadObject(ms);
Image1.ImageUrl = "http://openweathermap.org/img/w/"+Convert.ToString(weatherData.weather.icon)+".png";}
I am getting null in the icon but its not in the json it has a icon name specified