Sources: http://json2csharp.com/
public void GetCustomers()
{
WebRequest request = WebRequest.Create("http://northwind.servicestack.net/customers?format=json");
request.Method = "GET";
using (var response = request.GetResponse())
{
Stream responseStream = response.GetResponseStream();
using (var reader = new StreamReader(responseStream))
{
// get the response as text
string responseText = reader.ReadToEnd();
// convert from text
JavaScriptSerializer ser = new JavaScriptSerializer();
RootObject cust = ser.Deserialize<RootObject>(responseText);
}
}
}
}
public class Customer
{
public string Id { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
}
public class RootObject
{
public List<Customer> Customers { get; set; }
}
public void GetCustomers()
{
WebRequest request = WebRequest.Create("http://northwind.servicestack.net/customers?format=json");
request.Method = "GET";
using (var response = request.GetResponse())
{
Stream responseStream = response.GetResponseStream();
using (var reader = new StreamReader(responseStream))
{
// get the response as text
string responseText = reader.ReadToEnd();
// convert from text
JavaScriptSerializer ser = new JavaScriptSerializer();
RootObject cust = ser.Deserialize<RootObject>(responseText);
}
}
}
}
public class Customer
{
public string Id { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
}
public class RootObject
{
public List<Customer> Customers { get; set; }
}
No comments:
Post a Comment