我有一个json Url,但我有更多的Forenames。现在它只显示一个Forename。
public class details
{
public string id { get; set; }
public string name { get; set; }
public int lID { get; set; }
public string uuid { get; set; }
public string wpUID { get; set; }
public string fname { get; set; }
}
private void Form2_Load(object sender, EventArgs e){
var json1 = new WebClient().DownloadString("http://dev.ibeaconlivinglab.com:1881/showemployeesbyhu
urders?id=" + companyID);
List<details> detailsList = JsonConvert.DeserializeObject<List<details>>(json1);
foreach (details dets1 in detailsList)
{
label3.Text = dets1.fname;
this.Controls.Add(label3);
}
}
杰森:[ { &#34; id&#34;:1, &#34; fname&#34;:&#34; Jeff&#34;, }, { &#34; id&#34;:1, &#34; fname&#34;:&#34; Jan&#34;, }, { &#34; id&#34;:1, &#34; fname&#34;:&#34; Piet&#34;, } ]
答案 0 :(得分:2)
问题是代码一次又一次地更新相同的 label
。
尝试每个Label
创建新的detail
。
FlowLayoutPanel flowLayoutPanel1 = new FlowLayoutPanel();
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.WrapContents = false;
flowLayoutPanel1.AutoScroll = true;
this.Controls.Add(flowLayoutPanel1);
foreach (details dets1 in detailsList)
{
var label = new Label();
label.Name = dets1.fname;
label.Text = dets1.fname;
flowLayoutPanel1.Controls.Add(label);
}