Deserializing a JSON into a C# List of Objects - c#

I am trying to Deserialize a JSON from google places api. My custom class is set up as follows and my code looks like this. My Program throws no errors when running but my places object is null.
class PlacesDictionary
{
public void placesDictionary()
{ }
public Places GetPlaces()
{
Places places = new Places();
string apiKey = "I have an apiKey";
string googleUrl;
googleUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=43.038902,-87.906474&radius=500&type=restaurant&name=cruise&key=" + apiKey;
WebRequest request = WebRequest.Create(googleUrl);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
places = JsonConvert.DeserializeObject<Places>(responseFromServer);
Console.WriteLine(responseFromServer);
Console.ReadLine();
reader.Close();
dataStream.Close();
response.Close();
return places;
}
}
public class Places
{
public List<Place> places { get; set; }
public class Place
{
public Geometry geometry { get; set; }
public string icon { get; set; }
public string id { get; set; }
public string name { get; set; }
public OpeningHours opening_hours { get; set; }
public List<Photo> photos { get; set; }
public string place_id { get; set; }
public int price_level { get; set; }
public double rating { get; set; }
public string reference { get; set; }
public string scope { get; set; }
public List<string> types { get; set; }
public string vicinity { get; set; }
public class Location
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Northeast
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Southwest
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Viewport
{
public Northeast northeast { get; set; }
public Southwest southwest { get; set; }
}
public class Geometry
{
public Location location { get; set; }
public Viewport viewport { get; set; }
}
public class OpeningHours
{
public bool open_now { get; set; }
public List<object> weekday_text { get; set; }
}
public class Photo
{
public int height { get; set; }
public List<string> html_attributions { get; set; }
public string photo_reference { get; set; }
public int width { get; set; }
}
}
}

I think you should use
List<Place> places = JsonConvert.DeserializeObject<List<Place>>(responseFromServer);
instead of
places = JsonConvert.DeserializeObject<Places>(responseFromServer);
and don't forget remove following line
Places places = new Places();
Edit: Full Answer
static void Main(string[] args)
{
string apiKey = "your api key";
string googleUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=43.038902,-87.906474&radius=500&type=restaurant&name=cruise&key=" + apiKey;
WebRequest request = WebRequest.Create(googleUrl);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
//StreamWriter wr = new StreamWriter("json.txt");
//wr.WriteLine(responseFromServer);
//wr.Flush();
//To see what it is inside json
Result results = JsonConvert.DeserializeObject<Result>(responseFromServer);
Console.WriteLine(responseFromServer);
Console.ReadLine();
reader.Close();
dataStream.Close();
response.Close();
}
}
public class Result
{
public List<HTMLAttribution> html_attributions { get; set; }
public string next_page_token { get; set; }
public List<Place> results { get; set; }
public string status { get; set; }
//Definations of Classes
public class HTMLAttribution { } //I don't what it is. It is empty for your url.
public class Place
{
public Geometry geometry { get; set; }
public string icon { get; set; }
public string id { get; set; }
public string name { get; set; }
public OpeningHours opening_hours { get; set; }
public List<Photo> photos { get; set; }
public string place_id { get; set; }
public int price_level { get; set; }
public double rating { get; set; }
public string reference { get; set; }
public string scope { get; set; }
public List<string> types { get; set; }
public string vicinity { get; set; }
public class Geometry
{
public Location location { get; set; }
public Viewport viewport { get; set; }
}
public class Location
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Viewport
{
public Northeast northeast { get; set; }
public Southwest southwest { get; set; }
}
public class Northeast
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Southwest
{
public double lat { get; set; }
public double lng { get; set; }
}
public class OpeningHours
{
public bool open_now { get; set; }
public List<object> weekday_text { get; set; }
}
public class Photo
{
public int height { get; set; }
public List<string> html_attributions { get; set; }
public string photo_reference { get; set; }
public int width { get; set; }
}
}
}

I would try something (if I were you) :
delete
Places places = new Places();
replace
places = JsonConvert.DeserializeObject(responseFromServer);
by
Places places = JsonConvert.DeserializeObject(responseFromServer);
and add a default constructor in your class Places like you have add in PlacesDictionary.

1.Just have Place class only.
2.Initialize List<Place> places=new List<Place>()
3.Deserialize using places
places = JsonConvert.DeserializeObject<places>(responseFromServer);

Related

Grabbing Json Data to String in Gridview

I'm setting up a website ASPX file that grabs the weather for the next 3 days, the output is in JSON and their classes are too complicated for me to understand it. If I want to extract just the weather for the next 3 days how do I go on about doing that?
https://samples.openweathermap.org/data/2.5/forecast?q=London,us&appid=b6907d289e10d714a6e88b30761fae22
This is the JSON output displayed on top.
What I'm trying to accomplish is to extract the next 3 days of the weather "Description" and put it to a GridView. I have used a JSON beautifier to get the classes but I am still confused.
Any help would be appreciated
This is my current code and I'm stuck here
protected void Button1_Click(object sender, EventArgs e)
{
string searchTerm = TextBox1.Text;
var webRequest = (HttpWebRequest)WebRequest.Create("https://samples.openweathermap.org/data/2.5/forecast?q=" + Server.UrlEncode(searchTerm) + "&units=metric&APPID=b6907d289e10d714a6e88b30761fae22");
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode == HttpStatusCode.OK)
{
Label1.Text = "The Next 3 days of weather in your area in" + searchTerm + " .";
JavaScriptSerializer json = new JavaScriptSerializer();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string resString = sr.ReadToEnd();
});
GridView1.DataSource = ?;
GridView1.DataBind();
}
else
Label.Text = "Invalid Response";
}
public class Main
{
public double temp { get; set; }
public double temp_min { get; set; }
public double temp_max { get; set; }
public double pressure { get; set; }
public double sea_level { get; set; }
public double grnd_level { get; set; }
public int humidity { get; set; }
public double temp_kf { 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; }
}
public class Clouds
{
public int all { get; set; }
}
public class Wind
{
public double speed { get; set; }
public double deg { get; set; }
}
public class Sys
{
public string pod { get; set; }
}
public class Rain
{
public double __invalid_name__3h { get;
set; }
}
public class Snow
{
public double __invalid_name__3h { get;
set; }
}
public class List
{
public int dt { get; set; }
public Main main { get; set; }
public List<Weather> weather { get; set; }
public Clouds clouds { get; set; }
public Wind wind { get; set; }
public Sys sys { get; set; }
public string dt_txt { get; set; }
public Rain rain { get; set; }
public Snow snow { get; set; }
}
public class Coord
{
public double lat { get; set; }
public double lon { get; set; }
}
public class City
{
public int id { get; set; }
public string name { get; set; }
public Coord coord { get; set; }
public string country { get; set; }
}
public class RootObject
{
public string cod { get; set; }
public double message { get; set; }
public int cnt { get; set; }
public List<List> list { get; set; }
public City city { get; set; }
}

Incorrect JSON Output Using ASP.NET

Please excuse this question as a sign of frustration. While I understand that cause of the issue is the converting of data into different types, I can't put my finger on what's causing the result of this web service get method to be output incorrectly, that is containing backslashes.
The code below sums up the functionality of my method. I've tried different suggestions I found on these forums, some of which were in reply to similar questions I asked myself.
Data Model
public class WeatherResponse
{
public class Coord
{
public double lon { get; set; }
public double lat { 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; }
}
public class Main
{
public double temp { get; set; }
public int pressure { get; set; }
public int humidity { get; set; }
public int temp_min { get; set; }
public int temp_max { get; set; }
}
public class Wind
{
public double speed { get; set; }
public int deg { get; set; }
}
public class Clouds
{
public int all { get; set; }
}
public class Sys
{
public int type { get; set; }
public int id { get; set; }
public double message { get; set; }
public string country { get; set; }
public int sunrise { get; set; }
public int sunset { get; set; }
}
public class RootObject
{
public Coord coord { get; set; }
public List<WeatherResponse> weather { get; set; }
public string #base { get; set; }
public Main main { get; set; }
public int visibility { get; set; }
public Wind wind { get; set; }
public Clouds clouds { get; set; }
public int dt { get; set; }
public Sys sys { get; set; }
public int id { get; set; }
public string name { get; set; }
public int cod { get; set; }
}
}
Controller
[HttpGet]
public string Get(string city, string country)
{
string apiKey = "KEY";
HttpWebRequest apiRequest = WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + country + " &appid=" + apiKey + "&units=metric") as HttpWebRequest;
string apiResponse = "";
using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
apiResponse = reader.ReadToEnd();
}
Response.ContentType = "application/json";
return apiResponse;
}
Result
"{\"coord\":{\"lon\":-0.13,\"lat\":51.51},\"weather\":[{\"id\":521,\"main\":\"Rain\",\"description\":\"shower
rain\",\"icon\":\"09d\"}],\"base\":\"stations\",\"main\":{\"temp\":2.62,\"pressure\":991,\"humidity\":69,\"temp_min\":1,\"temp_max\":4},\"visibility\":10000,\"wind\":{\"speed\":5.1,\"deg\":90},\"clouds\":{\"all\":75},\"dt\":1548939000,\"sys\":{\"type\":1,\"id\":1414,\"message\":0.0037,\"country\":\"GB\",\"sunrise\":1548920401,\"sunset\":1548953318},\"id\":2643743,\"name\":\"London\",\"cod\":200}"
I need the code to simply retrieve weather data using the city and country received and correctly output it as JSON.
Here's the solution to the problem, as kindly posted by Joroen Mostert.
You should be able to use Content for this (when you change the return
type of your method to IActionResult): return Content(apiResponse,
"application/json") should not further escape.

How to extract data from a JSON array

I need some guidance here, my code works ok until I try to map the front tyre width to a label!!
How do you access the JSON array code below?
Code below
public class DVLA
{
public List<DVLAVehicle> cast { get; set; }
}
public class DVLAVehicle
{
[JsonProperty(PropertyName = "make")]
public string make { get; set; }
[JsonProperty(PropertyName = "model")]
public string model { get; set; }
[JsonProperty(PropertyName = "year")]
public int year { get; set; }
[JsonProperty(PropertyName = "frontTyres")]
public frontTyres[] frontTyres { get; set; }
[JsonProperty(PropertyName = "rearTyres")]
public rearTyres[] rearTyres { get; set; }
}
public class frontTyres
{
public int width { get; set; }
public int ratio { get; set; }
public string rim { get; set; }
public string speedRating { get; set; }
public int psi { get; set; }
public int loadIndex { get; set; }
}
var v1 = JsonConvert.DeserializeObject(TyreDetails);
lblmake.Text = v1.make;
lblmodel.Text = v1.model;
lblyear.Text = v1.year.ToString();
lblwidth.Text = v1.frontTyres.Width;

After deserialization getting null object C# Windows Phone

I was trying to play with an API. The API is returning the data in JSON.
Here is my code to make the request
private void makerequest()
{
HttpWebRequest request = HttpWebRequest.Create("http://grandtheftdata.com/bawsaq/api?a=DATA&o=JSON&p=PS3&t=2014-04-08T15:00:00Z," + now.ToString("YYYY-MM-DD") + "T" + now.ToString("HH:mm:ss") + "Z") as HttpWebRequest;
request.Method = "GET";
request.Accept = "application/json";
request.ContentLength = 0;
var playerResponse = request.BeginGetResponse(new AsyncCallback(getPlayer), request);
}
private void getPlayer(IAsyncResult ar)
{
try
{
string jsondata;
HttpWebRequest myHttpWebRequest = (HttpWebRequest)ar.AsyncState; ;
using (HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.EndGetResponse(ar))
{
System.IO.Stream responseStream = response.GetResponseStream();
using (var reader = new System.IO.StreamReader(responseStream))
{
jsondata = reader.ReadToEnd();
}
responseStream.Close();
}
this.Dispatcher.BeginInvoke(() =>
{
PS3BAWSAQ.RootObject feed = Newtonsoft.Json.JsonConvert.DeserializeObject<PS3BAWSAQ.RootObject>(jsondata);
MessageBox.Show(jsondata.Length + " characters");
}
);
}
catch (Exception e)
{
//Do something
}
}
and the JSON data it is returning in jsondata variable is
{
"data": {
"PS3": {
"2014-04-08T15:30:01Z": {
"AMU": 3.42,
"BDG": 6.73,
"BET": 716.1,
"BFA": 83.58,
"BIN": 3.82,
"BLE": 3591.3,
"BRU": 4.5,
"BTR": 3.51,
"CNT": 50.15,
"CRE": 2.5,
"DGP": 100.16,
"EYE": 3.68,
"FAC": 3.49,
"FRT": 3.86,
"GOT": 6.09,
"HAL": 3.58,
"HVY": 1.45,
"LSC": 1551.79,
"LST": 1045.54,
"LTD": 336.95,
"MAI": 348.5,
"PIS": 2.64,
"PMP": 2143.31,
"PON": 1700.82,
"RON": 323.46,
"SHK": 7.03,
"SHR": 1261.47,
"SHT": 582.65,
"SPU": 1607.05,
"SUB": 1509.58,
"TNK": 5.56,
"UMA": 4.47,
"VAP": 6.86,
"VOM": 1183.48,
"WAP": 88.74,
"WIW": 7.16,
"WIZ": 1.28,
"WZL": 999.98,
"ZIT": 3.46
}
}
},
"status": {
"code": 200,
"text": "ok"
}
}
And the classes generated by json2csharp.com are
public class __invalid_type__20140324T144502Z
{
public double AMU { get; set; }
public double BDG { get; set; }
public double BET { get; set; }
public double BFA { get; set; }
public double BIN { get; set; }
public double BLE { get; set; }
public double BRU { get; set; }
public double BTR { get; set; }
public double CNT { get; set; }
public double CRE { get; set; }
public double DGP { get; set; }
public double EYE { get; set; }
public double FAC { get; set; }
public double FRT { get; set; }
public double GOT { get; set; }
public double HAL { get; set; }
public double HVY { get; set; }
public double LSC { get; set; }
public double LST { get; set; }
public double LTD { get; set; }
public double MAI { get; set; }
public double PIS { get; set; }
public double PMP { get; set; }
public double PON { get; set; }
public double RON { get; set; }
public double SHK { get; set; }
public double SHR { get; set; }
public double SHT { get; set; }
public double SPU { get; set; }
public double SUB { get; set; }
public double TNK { get; set; }
public double UMA { get; set; }
public double VAP { get; set; }
public double VOM { get; set; }
public double WAP { get; set; }
public double WIW { get; set; }
public double WIZ { get; set; }
public double WZL { get; set; }
public double ZIT { get; set; }
}
public class PS3
{
public __invalid_type__20140324T144502Z __invalid_name__2014 { get; set; }
}
public class Data
{
public PS3 PS3 { get; set; }
}
public class Status
{
public int code { get; set; }
public string text { get; set; }
}
public class RootObject
{
public Data data { get; set; }
public Status status { get; set; }
}
The thing is I am not able to deserialize the JSON data to PS3BAWSAQ object properly.
And I am sure the problem is in the class name(invalid type). I changed their names but that didn't help either. The JSON has a member which is itself time dependent.
Can't figure a way to solve this. Please help.
The JsonConvert.Deserialize(string) method returns a dynamic object.
This is where you create your dynamic object
dynamic x = JsonConvert.DeserializeObject(jsondata);
Dynamic objects are really nice to work with. You can reference properties that the compiler have no clue exist or not. You can read about them here
You must parse the dynamic object like this.
Assuming that its only returning one of the above objects in the JSON
PS3BAWSAQ.RootObject obj = new PS3BAWSAQ.RootObject (){
Prop1 = x.Key1,
Prop2 = x.Key2,
//And So on
};
if its a list of objects you do it like this
foreach(PS3BAWSAQ.RootObject y in x){
PS3BAWSAQ.RootObject obj = new PS3BAWSAQ.RootObject (){
Prop1 = y.Key1,
Prop2 = y.Key2,
//And So on
};
}
if its a list of lists do it like this
foreach(var y in x.list1Name){
foreach(PS3BAWSAQ.RootObject z in y){
PS3BAWSAQ.RootObject obj = new PS3BAWSAQ.RootObject (){
Prop1 = z.Key1,
Prop2 = z.Key2,
//And So on
};
}
}
In your case it looks like its a single object being returned. So you would want option one. Just new up a new container and set each property individually. THE KEYS ARE CASE SENSITIVE!!!

How can I deserialize an XML response to an object when I only need a child element of the XML?

I have the following XML that I am getting back from a WebRequest:
<?xml version="1.0" encoding="UTF-8"?>
<search>
<total_items>5</total_items>
<page_size>10</page_size>
<page_count>1</page_count>
<page_number>1</page_number>
<page_items></page_items>
<first_item></first_item>
<last_item></last_item>
<search_time>0.044</search_time>
<events>
<event id="E0-001-053379749-0">
<title>Antibalas</title>
<url>http://test.com</url>
<description>stuff</description>
<start_time>2013-01-30 20:00:00</start_time>
<stop_time></stop_time>
<tz_id></tz_id>
<tz_olson_path></tz_olson_path>
<tz_country></tz_country>
<tz_city></tz_city>
<venue_id>V0-001-000189211-5</venue_id>
<venue_url>http://blah.com</venue_url>
<venue_name>Troubadour</venue_name>
<venue_display>1</venue_display>
<venue_address>9081 Santa Monica Boulevard</venue_address>
<city_name>West Hollywood</city_name>
<region_name>California</region_name>
<region_abbr>CA</region_abbr>
<postal_code>90069</postal_code>
<country_name>United States</country_name>
<country_abbr2>US</country_abbr2>
<country_abbr>USA</country_abbr>
<latitude>34.0815917</latitude>
<longitude>-118.3892462</longitude>
<geocode_type>EVDB Geocoder</geocode_type>
<all_day>0</all_day>
<recur_string></recur_string>
<calendar_count></calendar_count>
<comment_count></comment_count>
<link_count></link_count>
<going_count></going_count>
<watching_count></watching_count>
<created>2012-12-24 11:40:43</created>
<owner>evdb</owner>
<modified>2013-01-14 21:08:04</modified>
<performers>
<performer>
<id>P0-001-000000517-4</id>
<url>http://test.com</url>
<name>Antibalas</name>
<short_bio>Afro-beat / Funk / Experimental</short_bio>
<creator>jfisher</creator>
<linker>evdb</linker>
</performer>
</performers>
<image>
<url>http://s4.evcdn.com/images/small/I0-001/000/070/311-5.jpeg_/antibalas-11.jpeg</url>
<width>48</width>
<height>48</height>
<caption></caption>
<thumb>
<url>http://s4.evcdn.com/images/thumb/I0-001/000/070/311-5.jpeg_/antibalas-11.jpeg</url>
<width>48</width>
<height>48</height>
</thumb>
<small>
<url>http://s4.evcdn.com/images/small/I0-001/000/070/311-5.jpeg_/antibalas-11.jpeg</url>
<width>48</width>
<height>48</height>
</small>
<medium>
<url>http://s4.evcdn.com/images/medium/I0-001/000/070/311-5.jpeg_/antibalas-11.jpeg</url>
<width>128</width>
<height>128</height>
</medium>
</image>
<privacy>1</privacy>
<calendars></calendars>
<groups></groups>
<going></going>
</event>
</events>
</search>
I have created the following classes:
public class EventSearch
{
public int total_items { get; set; }
public int page_size { get; set; }
public int page_count { get; set; }
public int page_number { get; set; }
public int page_items { get; set; }
public string first_item { get; set; }
public string last_item { get; set; }
public string search_time { get; set; }
public List<Event> events { get; set; }
}
public class Event
{
public string id { get; set; }
public string title { get; set; }
public string url { get; set; }
public string description { get; set; }
public DateTime start_time { get; set; }
public string venue_id { get; set; }
public string venue_url { get; set; }
public string venue_name { get; set; }
public string venue_address { get; set; }
public string city_name { get; set; }
public string region_name { get; set; }
public string region_abbr { get; set; }
public string postal_code { get; set; }
public string country_name { get; set; }
public string country_abbr { get; set; }
public string country_abbr2 { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
public List<Performer> performers { get; set; }
public EventImage image { get; set; }
}
public class Performer
{
public string id { get; set; }
public string url { get; set; }
public string name { get; set; }
public string short_bio { get; set; }
}
public class EventImage
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
public Image thumb { get; set; }
public Image small { get; set; }
public Image medium { get; set; }
}
public class Image
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
In the method that I am calling, I want to return a list of events. Here's what I have so far, which is giving me the error:
was not expected.
Code:
var request = WebRequest.Create(url);
var response = request.GetResponse();
if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK)
{
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader.
StreamReader reader = new StreamReader(dataStream);
XmlSerializer serializer = new XmlSerializer(typeof(EventSearch));
EventSearch deserialized = (EventSearch)serializer.Deserialize(reader);
return deserialized.events;
}
I'm not sure what to do next. Do I need to annotate my classes?
Yes, you will need to add some Attributes to your classes to map the xml elements to your objects.
This should work, However I had to change a few things, The DateTime in the Xml is in the wrong fromat so I made it a string(you can parse as needed), also page_items is an int but it is an empty element in the xml, you wont be able to deserialize this, you will have to change to a string if it has a chance of being empty.
[XmlType("search")]
public class EventSearch
{
public int total_items { get; set; }
public int page_size { get; set; }
public int page_count { get; set; }
public int page_number { get; set; }
// public int? page_items { get; set; }
public string first_item { get; set; }
public string last_item { get; set; }
public string search_time { get; set; }
public List<Event> events { get; set; }
}
[XmlType("event")]
public class Event
{
[XmlAttribute("id")]
public string id { get; set; }
public string title { get; set; }
public string url { get; set; }
public string description { get; set; }
public string start_time { get; set; }
public string venue_id { get; set; }
public string venue_url { get; set; }
public string venue_name { get; set; }
public string venue_address { get; set; }
public string city_name { get; set; }
public string region_name { get; set; }
public string region_abbr { get; set; }
public string postal_code { get; set; }
public string country_name { get; set; }
public string country_abbr { get; set; }
public string country_abbr2 { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
public List<Performer> performers { get; set; }
public EventImage image { get; set; }
}
[XmlType("performer")]
public class Performer
{
public string id { get; set; }
public string url { get; set; }
public string name { get; set; }
public string short_bio { get; set; }
}
[XmlType("image")]
public class EventImage
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
public Image thumb { get; set; }
public Image small { get; set; }
public Image medium { get; set; }
}
[XmlType("thumb")]
public class Image
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
I tested directly from file using:
using (FileStream stream = new FileStream("C:\\Test.xml", FileMode.Open))
{
XmlSerializer serializer = new XmlSerializer(typeof(EventSearch));
EventSearch deserialized = (EventSearch)serializer.Deserialize(stream);
}
But your Stream from the Webresponce should work the same as the FileStream
Hope this helps :)

Categories

Resources