Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 循环浏览json url_C#_Json_Loops - Fatal编程技术网

C# 循环浏览json url

C# 循环浏览json url,c#,json,loops,C#,Json,Loops,我有一个json Url,但我有更多的名字。现在它只显示一个名字 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

我有一个json Url,但我有更多的名字。现在它只显示一个名字

    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);

        }
公共类详细信息
{
公共字符串id{get;set;}
公共字符串名称{get;set;}
公共整数lID{get;set;}
公共字符串uuid{get;set;}
公共字符串wpUID{get;set;}
公共字符串fname{get;set;}
}
私有void Form2_加载(对象发送方、事件参数e){
var json1=新的WebClient()。下载字符串(“http://dev.ibeaconlivinglab.com:1881/showemployeesbyhu  
urders?id=“+companyID”);
List detailsList=JsonConvert.DeserializeObject(json1);
foreach(详细信息列表中的详细信息1)
{
label3.Text=dets1.fname;
this.Controls.Add(label3);
}
}

Json:

[ { “id”:1, “fname”:“Jeff”, }, { “id”:1, “fname”:“Jan”, }, { “id”:1, “fname”:“Piet”, }
]问题是代码一次又一次地更新相同的
标签

尝试创建新的
标签
每个
细节

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);   
} 

问题是代码一次又一次地更新相同的
标签

尝试创建新的
标签
每个
细节

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);   
} 

您是否尝试在
console.log(json1)
的帮助下调试服务器返回的json字符串?@daniela yeh I Did您是否尝试在
console.log(json1)的帮助下调试服务器返回的json字符串
?@daniela yeh我刚才试过了,结果得到了两个相同的名字。你能看到其他名字吗?不,我看到了名字“jeff”twiceI copied:var label=new label();label.Name=dets1.fname;//试着保持它的独特性。label.Text=dets1.fname;this.Controls.Add(标签);并将标签名称更改为label1I我看不出任何原因它只显示两个同名的标签,您的json有3个条目,因此您应该看到3个标签。我刚刚尝试了这一点,结果得到了两个相同的名称。您能看到任何其他名称吗?不,我看到名称“jeff”twiceI copied:var label=new label();label.Name=dets1.fname;//试着保持它的独特性。label.Text=dets1.fname;this.Controls.Add(标签);将label name改为label1I我看不出任何原因,它只显示了两个同名的标签,您的json有3个条目,所以您应该看到3个标签。