表company
有50列。前5列为time, company_type, company_id, status, established_date
。接下来的45列是:employee0, employee1, employee2, ..., employee44
。这45列的值为integer
类型。我需要将这45列的格式设置为JSON
,如下所示:
'{"employee0":"2", "employee1":"4", "employee2":"6", ... , "employee44":"101"}'
在下面的脚本中,我创建了一个包含雇员的变量chRow
。 chRow
与i
串联,每次运行时递增。但是,row.temp
(实际上应该是row.employee<i>
)给出了unspecified
,而chRow
则显示为chRow
,而不是每次迭代都分配给它的值。非常感谢我如何创建JSON数组的任何帮助。
db.each(`SELECT * FROM company`, (err, row) => {
if (err) { throw err; }
var i;
var chRow = "employee";
var jsonArr = [];
for (var i = 0; i < (row.length-5); i++) {
temp = chRow+i
jsonArr.push({
chRow : row.temp //I would like this to be as follows - channel0: 2 or channel1: 4 or so on depending on i value
});
}
JSON.parse(jsonArr);
});