如何在每次迭代中使用一个单独的事件处理程序,而不对函数进行硬编码?
for (int i = 0; i < 100; i++)
{
//other code
PictureBox listItem = new PictureBox();
listItem.Click += new EventHandler((sender2, e2) => ListItemClicked(i));
//other code
}
Run Code Online (Sandbox Code Playgroud)
private void ListItemClicked(int index)
{
MessageBox.Show(index.ToString());
}
Run Code Online (Sandbox Code Playgroud) var clients = [];
var tmp = [];
tmp["username"] = rows[0].username;
tmp["rank"] = rows[0].rank;
tmp["lastaction"] = "0";
tmp["connection"] = connection;
clients.push(tmp);
JSON.stringify(clients)
Run Code Online (Sandbox Code Playgroud)
我初始化了一个数组(客户端)并将关联数组(tmp)推送到客户端数组。但如果我“字符串化”客户端,它只会返回“[[]]”。
我做错了什么?
先感谢您。
JSON string:
[{"id":"1","username":"admin","password":"anymd5hash","rank":"2"}]
following code:
Newtonsoft.Json.Linq.JObject userData;
userData = Newtonsoft.Json.Linq.JObject.Parse(result);
MessageBox.Show(userData["username"].ToString());
Run Code Online (Sandbox Code Playgroud)
When I execute this code, there will be an error:
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
I'm pretty sure, that this code has worked in another project.
What is my mistake?