I have this simple method that allows me to get weather data when I call it an error:
System.Runtime.Serialization.SerializationException is not handled by user code HResult = -2146233076 Message = Error deserializing an object of type UWpWeather.RootObject. An unexpected '<' was detected.
public async static Task <RootObject> GetWeather(double lat, double lng) { var http = new HttpClient(); var response = await http.GetAsync("http://api.openweathermap.org/data/2.5/forecast/daily?q=leeds&type=accurate&mode=xml&units=metric&cnt=3&appid= MY AIP-KEY"); string result = await response.Content.ReadAsStringAsync(); var serializer = new DataContractJsonSerializer(typeof (RootObject)); var ms = new MemoryStream(Encoding.UTF8.GetBytes(result)); var data = (RootObject) serializer.ReadObject(ms); return data; }
The API does not honor any HTTP content or Accept headers that you pass on request, but rather sets the type of response content based on the request string parameter.
Your start URL:
http://api.openweathermap.org/data/2.5/forecast/daily?q=leeds&type=accurate&mode= xml & units = metric & cnt = 3 & appid = MY AIP-KEY "
:
http://api.openweathermap.org/data/2.5/forecast/daily?q=leeds&type=accurate&mode= json & units = metric & cnt = 3 & appid = MY AIP-KEY "
RootObject .
RootObject
: , JSON.
, Xml Json . -, (json2csharp), Json , Json, , , public List<List> list { get; set; } , . .
public List<List> list { get; set; }
Source: https://habr.com/ru/post/1675993/More articles:How to use Rails 5.1.0 and jQuery - ruby | fooobar.comHow to mock / replace an object getter function using Jest? - javascriptChange the orientation of a group of buttons vertically / horizontally using BS4 classes - twitter-bootstrap-4Обмен сообщениями с помощью Java - Python - javahow can I access __zone_symbol__value in ZoneAwarePromise in Angular 2 - angularMake class serializable in PCL - c #how to set default value as guid when field is empty during deserialization - jsonHow to understand H2OModelMetrics object metrics through h2o.performance - rAWS API Gateway + AWS ECS + OAuth2 Password Grant - javaWhy is the ELF header loaded into memory along with the text segment? - cAll Articles