Note that there are some explanatory texts on larger screens.

plurals
  1. POCan not deserialize Xml getting from api
    primarykey
    data
    text
    <p>I am using World Weather Online API to get the weathers of specific location. My problem is while I am trying to deserialize XML output coming from API Response stream, I am getting error with: There is a problem with XML document (1,1).</p> <pre><code> Uri apiURL = new Uri(@"http://api.worldweatheronline.com/free/v1/weather.ashx?q=Dhaka&amp;format=xml&amp;num_of_days=1&amp;date=today&amp;key=jzb88bpzb5yvaegukmq97mee"); Stream result = RequestHandler.Process(apiURL.ToString()); XmlSerializer des = new XmlSerializer(typeof(LocalWeather)); StreamReader tr = new StreamReader(result); Object obj = des.Deserialize(tr); LocalWeather data = (LocalWeather)obj; </code></pre> <p>Sample XML file from Web API:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;data&gt; &lt;request&gt; &lt;type&gt;City&lt;/type&gt; &lt;query&gt;Dhaka, Bangladesh&lt;/query&gt; &lt;/request&gt; &lt;current_condition&gt; &lt;observation_time&gt;01:57 PM&lt;/observation_time&gt; &lt;temp_C&gt;33&lt;/temp_C&gt; &lt;temp_F&gt;91&lt;/temp_F&gt; &lt;weatherCode&gt;113&lt;/weatherCode&gt; &lt;weatherIconUrl&gt; &lt;![CDATA[http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0008_clear_sky_night.png]]&gt; &lt;/weatherIconUrl&gt; &lt;weatherDesc&gt; &lt;![CDATA[Clear ]]&gt; &lt;/weatherDesc&gt; &lt;windspeedMiles&gt;2&lt;/windspeedMiles&gt; &lt;windspeedKmph&gt;4&lt;/windspeedKmph&gt; &lt;winddirDegree&gt;77&lt;/winddirDegree&gt; &lt;winddir16Point&gt;ENE&lt;/winddir16Point&gt; &lt;precipMM&gt;0.0&lt;/precipMM&gt; &lt;humidity&gt;76&lt;/humidity&gt; &lt;visibility&gt;10&lt;/visibility&gt; &lt;pressure&gt;1006&lt;/pressure&gt; &lt;cloudcover&gt;2&lt;/cloudcover&gt; &lt;/current_condition&gt; &lt;weather&gt; &lt;date&gt;2013-10-11&lt;/date&gt; &lt;tempMaxC&gt;36&lt;/tempMaxC&gt; &lt;tempMaxF&gt;97&lt;/tempMaxF&gt; &lt;tempMinC&gt;25&lt;/tempMinC&gt; &lt;tempMinF&gt;77&lt;/tempMinF&gt; &lt;windspeedMiles&gt;5&lt;/windspeedMiles&gt; &lt;windspeedKmph&gt;8&lt;/windspeedKmph&gt; &lt;winddirection&gt;ENE&lt;/winddirection&gt; &lt;winddir16Point&gt;ENE&lt;/winddir16Point&gt; &lt;winddirDegree&gt;65&lt;/winddirDegree&gt; &lt;weatherCode&gt;113&lt;/weatherCode&gt; &lt;weatherIconUrl&gt; &lt;![CDATA[http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0001_sunny.png]]&gt; &lt;/weatherIconUrl&gt; &lt;weatherDesc&gt; &lt;![CDATA[Sunny]]&gt; &lt;/weatherDesc&gt; &lt;precipMM&gt;0.0&lt;/precipMM&gt; &lt;/weather&gt; &lt;/data&gt; </code></pre> <p>LocalWeather class:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace APISample { public class LocalWeather { public Data data { get; set; } } public class Data { public List&lt;Current_Condition&gt; current_Condition { get; set; } public List&lt;Request&gt; request { get; set; } public List&lt;Weather&gt; weather { get; set; } } public class Current_Condition { public DateTime observation_time { get; set; } public DateTime localObsDateTime { get; set; } public int temp_C { get; set; } public int windspeedMiles { get; set; } public int windspeedKmph { get; set; } public int winddirDegree { get; set; } public string winddir16Point { get; set; } public string weatherCode { get; set; } public List&lt;WeatherDesc&gt; weatherDesc { get; set; } public List&lt;WeatherIconUrl&gt; weatherIconUrl { get; set; } public float precipMM { get; set; } public float humidity { get; set; } public int visibility { get; set; } public int pressure { get; set; } public int cloudcover { get; set; } } public class Request { public string query { get; set; } public string type { get; set; } } public class Weather { public DateTime date { get; set; } public int tempMaxC { get; set; } public int tempMaxF { get; set; } public int tempMinC { get; set; } public int tempMinF { get; set; } public int windspeedMiles { get; set; } public int windspeedKmph { get; set; } public int winddirDegree { get; set; } public string winddir16Point { get; set; } public string weatherCode { get; set; } public List&lt;WeatherDesc&gt; weatherDesc { get; set; } public List&lt;WeatherIconUrl&gt; weatherIconUrl { get; set; } public float precipMM { get; set; } } public class WeatherDesc { public string value { get; set; } } public class WeatherIconUrl { public string value { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload