请求JSON数据:
private async void InitDataJson() { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await httpClient.GetAsync(new Uri(":64339/api/books")); response.EnsureSuccessStatusCode(); string result = await response.Content.ReadAsStringAsync(); List<Books> bookslist = new List<Books>(); JsonArray arrays = JsonArray.Parse(result); for (int i = 0; i < arrays.Count; i++) { JsonObject obj = arrays.GetObjectAt((uint)i); bookslist.Add(new Books() { book_Name =obj.GetNamedString("book_Name"), book_Author = obj.GetNamedString("book_Author"), book_Isbn = obj.GetNamedString("book_Isbn"), book_cate =obj.GetNamedString("book_cate"), book_Press = obj.GetNamedString("book_Press"), book_Rressdate = obj.GetNamedString("book_Rressdate"), book_Remain = Convert.ToInt32(obj.GetNamedNumber("book_Remain")) }); } listView.ItemsSource = bookslist; }Book.cs:
public class Books { public int book_Id { get; set; } public string book_Name { get; set; } public string book_Author { get; set; } public string book_Isbn { get; set; } public string book_cate { get; set; } public string book_Press { get; set; } public string book_Rressdate { get; set; } public int book_Remain { get; set; } } View Code运行结果:
借助于ASP.NET Web API,我们最终将SQL Server数据库中的数据通过UWP应用进行了展示。(我发现最后的这个图表示的意思有点不够,懒得换了,懒)
好了,这就是本次的全部内容了,貌似有点乱,要Demo的留邮箱。太晚了,睡觉了,晚安!