ASP.NET MVC 4 Web API – Restful Web Services ( JSON ) : GET 方法
Web API Controller |
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace MvcApplication { public class APIController : ApiController { // GET api/<controller> public List<product> Get() { List<product> list = new List<product>(); product item; for (int i = 1; i < 100; i++) { item = new product(); item.id = i; item.cat = "Cat " + i; item.subcat = "Subcat " + i; item.model = "Model " + i; item.price = i * 100; list.Add(item); } return list; } … … } public class product { public int id { get; set; } public string cat { get; set; } public string subcat { get; set; } public string model { get; set; } public Nullable<long> price { get; set; } } } |