using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JSON解析练习
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static HttpClient http = new HttpClient();
private async void button1_Click(object sender, EventArgs e)
{
try
{
HttpResponseMessage httpResponseMessage = await http.GetAsync("http://192.168.107.20:3000/Shop");
httpResponseMessage.EnsureSuccessStatusCode();
string s = await httpResponseMessage.Content.ReadAsStringAsync();
Sh sh = JsonConvert.DeserializeObject<Sh>(s);
this.dataGridView1.DataSource = sh.data;
for (int i = 0; i < sh.data.Count; i++)
{
using (WebClient webClient = new WebClient())
{
byte[] bs = webClient.DownloadData(sh.data[i].topImg);
using (MemoryStream ms = new MemoryStream(bs))
{
Image im=Image.FromStream(ms);
this.dataGridView1.Rows[i].Cells[2].Value = im;
}
}
}
}
catch (Exception rr)
{
throw rr;
}
}
}
public class Sh
{
public int code { get; set; }
public string message { get; set; }
public List<D1> data { get; set; }
}
public class D1
{
public int productId { get; set; }
public string productName { get; set; }
public string topImg { get; set; }
public bool isActivity { get; set; }
public bool isCard { get; set; }
public bool isSeven { get; set; }
public bool isRealDesc { get; set; }
public string spec { get; set; }
public int price { get; set; }
public int count { get; set; }
public int amount { get; set; }
}
}
//productId: 1001,
// // 商品名称
// productName: "【64GB限时优惠100元】华为旗下荣耀Play4T手机新品大电池AI摄影",
// // 是否参加电竞节
// isActivity: true,
// // 是否支持信用卡
// isCard: true,
// // 是否支持七天退货
// isSeven: true,
// // 是否如实描述
// isRealDesc: true,
// // 规格
// spec: "网络类型:4G全网通<br>机身颜色:极光蓝<br>套餐类型:官方标配<br>存储容量:6+128GB",
// // 单价
// price: 1199.00,
// // 购买的数量
// count: 2,
// // 金额
// amount: 2398.00