У меня десериализация с использованием xmlserializer, но с datacontract у меня нет идеи, мне нужно десериализовать с Datacontract Как десериализовать с datacontract этим wather api.
Что я должен использовать, может кто-нибудь помочь мне, пожалуйста?
результат десериализации с помощью xml сериализатор
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Xml;
using RestSharp;
using RestSharp.Deserializers;
using System.IO;
namespace DataContractd
{
class Program
{
static void Main(string[] args)
{
var clientWeather = new RestClient("http://api.worldweatheronline.com/premium/v1/weather.ashx");
var requestWeather = new RestRequest(Method.GET);
requestWeather.AddParameter("key", "-removed-", ParameterType.QueryString);
requestWeather.AddParameter("q", "Pristina", ParameterType.QueryString);
requestWeather.AddParameter("format", "xml", ParameterType.QueryString);
requestWeather.AddParameter("num_of_days", "5", ParameterType.QueryString);
var responseWeather = clientWeather.Execute(requestWeather);
var xmlDeserializer = new XmlDeserializer();
var place = xmlDeserializer.Deserialize<Request>(responseWeather);
var temp = xmlDeserializer.Deserialize<Current_condition>(responseWeather);
var days = xmlDeserializer.Deserialize<List<Weather>>(responseWeather);
var data1 = xmlDeserializer.Deserialize<Data>(responseWeather);
Console.WriteLine("Place: " + place.Query);
Console.WriteLine("Temp momentale: " + temp.FeelsLikeC);
foreach (var write in days)
{
Console.WriteLine(write.Date + " " + write.MintempC + " " + write.MaxtempC);
}
//how to Deserialize with datacontract
//DataContractSerializer Deserialize = new DataContractSerializer(typeof(responseWeather))
}
}
[DataContract]
public class Request
{
[DataMember]
public string Type { get; set; }
[DataMember]
public string Query { get; set; }
}
[DataContract]
public class Current_condition
{
[DataMember]
public string Observation_time { get; set; }
[DataMember]
public string Temp_C { get; set; }
[DataMember]
public string Temp_F { get; set; }
[DataMember]
public string WeatherCode { get; set; }
[DataMember]
public string WeatherIconUrl { get; set; }
[DataMember]
public string WeatherDesc { get; set; }
[DataMember]
public string WindspeedMiles { get; set; }
[DataMember]
public string WindspeedKmph { get; set; }
[DataMember]
public string WinddirDegree { get; set; }
[DataMember]
public string Winddir16Point { get; set; }
[DataMember]
public string PrecipMM { get; set; }
[DataMember]
public string PrecipInches { get; set; }
[DataMember]
public string Humidity { get; set; }
[DataMember]
public string Visibility { get; set; }
[DataMember]
public string VisibilityMiles { get; set; }
[DataMember]
public string Pressure { get; set; }
[DataMember]
public string PressureInches { get; set; }
[DataMember]
public string Cloudcover { get; set; }
[DataMember]
public string FeelsLikeC { get; set; }
[DataMember]
public string FeelsLikeF { get; set; }
[DataMember]
public string UvIndex { get; set; }
}
[DataContract]
public class Astronomy
{
[DataMember]
public string Sunrise { get; set; }
[DataMember]
public string Sunset { get; set; }
[DataMember]
public string Moonrise { get; set; }
[DataMember]
public string Moonset { get; set; }
[DataMember]
public string Moon_phase { get; set; }
[DataMember]
public string Moon_illumination { get; set; }
}
[DataContract]
public class Hourly
{
[DataMember]
public string Time { get; set; }
[DataMember]
public string TempC { get; set; }
[DataMember]
public string TempF { get; set; }
[DataMember]
public string WindspeedMiles { get; set; }
[DataMember]
public string WindspeedKmph { get; set; }
[DataMember]
public string WinddirDegree { get; set; }
[DataMember]
public string Winddir16Point { get; set; }
[DataMember]
public string WeatherCode { get; set; }
[DataMember]
public string WeatherIconUrl { get; set; }
[DataMember]
public string WeatherDesc { get; set; }
[DataMember]
public string PrecipMM { get; set; }
[DataMember]
public string PrecipInches { get; set; }
[DataMember]
public string Humidity { get; set; }
[DataMember]
public string Visibility { get; set; }
[DataMember]
public string VisibilityMiles { get; set; }
[DataMember]
public string Pressure { get; set; }
[DataMember]
public string PressureInches { get; set; }
[DataMember]
public string Cloudcover { get; set; }
[DataMember]
public string HeatIndexC { get; set; }
[DataMember]
public string HeatIndexF { get; set; }
[DataMember]
public string DewPointC { get; set; }
[DataMember]
public string DewPointF { get; set; }
[DataMember]
public string WindChillC { get; set; }
[DataMember]
public string WindChillF { get; set; }
[DataMember]
public string WindGustMiles { get; set; }
[DataMember]
public string WindGustKmph { get; set; }
[DataMember]
public string FeelsLikeC { get; set; }
[DataMember]
public string FeelsLikeF { get; set; }
[DataMember]
public string Chanceofrain { get; set; }
[DataMember]
public string Chanceofremdry { get; set; }
[DataMember]
public string Chanceofwindy { get; set; }
[DataMember]
public string Chanceofovercast { get; set; }
[DataMember]
public string Chanceofsunshine { get; set; }
[DataMember]
public string Chanceoffrost { get; set; }
[DataMember]
public string Chanceofhightemp { get; set; }
[DataMember]
public string Chanceoffog { get; set; }
[DataMember]
public string Chanceofsnow { get; set; }
[DataMember]
public string Chanceofthunder { get; set; }
[DataMember]
public string UvIndex { get; set; }
}
[DataContract]
public class Weather
{
[DataMember]
public string Date { get; set; }
[DataMember]
public Astronomy Astronomy { get; set; }
[DataMember]
public string MaxtempC { get; set; }
[DataMember]
public string MaxtempF { get; set; }
[DataMember]
public string MintempC { get; set; }
[DataMember]
public string MintempF { get; set; }
[DataMember]
public string AvgtempC { get; set; }
[DataMember]
public string AvgtempF { get; set; }
[DataMember]
public string TotalSnow_cm { get; set; }
[DataMember]
public string SunHour { get; set; }
[DataMember]
public string UvIndex { get; set; }
[DataMember]
public List<Hourly> Hourly { get; set; }
}
[DataContract]
public class Month
{
[DataMember]
public string Index { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string AvgMinTemp { get; set; }
[DataMember]
public string AvgMinTemp_F { get; set; }
[DataMember]
public string AbsMaxTemp { get; set; }
[DataMember]
public string AbsMaxTemp_F { get; set; }
[DataMember]
public string AvgDailyRainfall { get; set; }
}
[DataContract]
public class ClimateAverages
{
[DataMember]
public List<Month> Month { get; set; }
}
[DataContract]
public class Data
{
[DataMember]
public Request Request { get; set; }
[DataMember]
public Current_condition Current_condition { get; set; }
[DataMember]
public List<Weather> Weather { get; set; }
[DataMember]
public ClimateAverages ClimateAverages { get; set; }
}
У меня десериализация с использованием xmlserializer, но с datacontract у меня нет идеи, мне нужно десериализовать с Datacontract Как десериализовать с Datacontract это wather api.