小编Ree*_*ese的帖子

c# for-loop 和 Click 事件处理程序

如何在每次迭代中使用一个单独的事件处理程序,而不对函数进行硬编码?

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)

c# picturebox eventhandler

4
推荐指数
1
解决办法
842
查看次数

JSON.stringify:JSON 字符串将为空

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)推送到客户端数组。但如果我“字符串化”客户端,它只会返回“[[]]”。

我做错了什么?

先感谢您。

javascript json node.js

3
推荐指数
1
解决办法
2791
查看次数

Error during JSON parsing

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?

c# json json.net

0
推荐指数
1
解决办法
4581
查看次数

标签 统计

c# ×2

json ×2

eventhandler ×1

javascript ×1

json.net ×1

node.js ×1

picturebox ×1