Hi,
Today I have a code that retrieves the JSON data from a URL. It works perfectly.
But now I want to do just the same, but I want to retrieve from an XML instead of JSON.
How do I do it the best way?
Thanks in advance,
Json URL: http://api.namnapi.se/v2/names.json?limit=3
XML URL: http://api.namnapi.se/v2/names.xml?limit=3
public class Data
{
public List<Objects> names { get; set; }
}
public class Objects
{
public string firstname { get; set; }
public string surname { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
WebClient client = new WebClient();
string json = client.DownloadString("http://api.namnapi.se/v2/names.json?limit=3");
Data result = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Data>(json);
foreach (var item in result.names)
{
Label.Text += (item.firstname + " " + item.surname + "<br />");
}
}