Ree*_*ese 3 javascript json node.js
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)推送到客户端数组。但如果我“字符串化”客户端,它只会返回“[[]]”。
我做错了什么?
先感谢您。
您应该转向tmp对象文字而不是数组文字。
var clients = [];
var tmp = {};
tmp["username"] = "foo";
tmp["rank"] = 1;
tmp["lastaction"] = "0";
tmp["connection"] = "bar";
clients.push(tmp);
console.log(JSON.stringify(clients))Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2791 次 |
| 最近记录: |