Bauhaus
Well-known member
Ik heb dit stukje code om webdata in een JSON file te steken maar omgekeerd wil hij niet de Title van de class Movie tonen:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.themoviedb.org/3/movie/tt1872181?api_key=" + "2d5a19e1c6ac7cc2aa6917f3f4cad042");
// Send the request and wait for response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the response stream
Stream responseStream = response.GetResponseStream();
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(movie));
object objResponse = (movie)jsonSerializer.ReadObject(responseStream);
movie jsonResponse = objResponse as movie;
//jsonResponse.Title;
Console.Write(jsonResponse.Title);
Console.ReadKey();
response.Close();
}
}
}
[DataContract]
class movie
{
[DataMember]
public string Title { get; set; }
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.themoviedb.org/3/movie/tt1872181?api_key=" + "2d5a19e1c6ac7cc2aa6917f3f4cad042");
// Send the request and wait for response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the response stream
Stream responseStream = response.GetResponseStream();
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(movie));
object objResponse = (movie)jsonSerializer.ReadObject(responseStream);
movie jsonResponse = objResponse as movie;
//jsonResponse.Title;
Console.Write(jsonResponse.Title);
Console.ReadKey();
response.Close();
}
}
}
[DataContract]
class movie
{
[DataMember]
public string Title { get; set; }
}