我有一个Node.js应用程序,它将数据写入MySQL后端。一个字段是一个字符串化的数组。我可以在工作台中看到数据在数据库中是正确的。但是,当我检索它时,我尝试解析它时收到错误。
“位置1的JSON中出现意外的令牌o”
如果我记录结果,则显示为[Object Object]
。
从我在网上看到的,这意味着它已经是一个JS对象了,我不需要解析它。但是,我找不到任何有关如何访问数据的信息。
process: function (bot, msg, suffix) {
var ftcmds = suffix.split(" ", 1);
var ftName = ftcmds[0];
var ftArray;
var selectSQL = "SELECT FireTeam FROM fireteam WHERE Name = '" + ftName + "'";
var updateSQL = "UPDATE fireteam SET FireTeam = '" + ftArray + "'WHERE Name = '" + ftName + "'";
mysqlcon.query(selectSQL, function (err, result) {
console.log("Result |" + result);
console.log("Error |" + err);
if (err) {
console.log("Caught Error " + err + " " + msg.author);
}
else {
console.log("Recovered result " + result);
ftArray = result;
console.log("Attempting to update array");
ftArray.push(msg.author.id);
console.log("updated array " + ftArray);
var jsonArray = JSON.stringify(ftArray);
mysqlcon.query(updateSQL, function (err, result) {
console.log("Result |" + result);
console.log("Error |" + err);
if (err.toString().indexOf(dupErr) != -1) {
msg.author.send("Could not find that fireteam");
console.log("Error: Did not locate the requested name " + msg.author)
} else if (err) {
console.log("Caught Error " + err + " " + msg.author);
}
else {
msg.author.send("You have joined Fireteam " + name + ". I will setup a group chat on " + date + " if your team fills up.");
}
})
}
});
}
答案 0 :(得分:1)
您应该只能将其作为对象进行访问,因此如果结果包含字段名称和标题,则只需访问它们:
Select Case Me!frmFilter.Value
Case 1 'All
Forms![InventoryList]![InventoryList subform].Form.FilterOn = False
Case 2 'Active
strFilter = "[StartDate] > Date()"
Forms![InventoryList]![InventoryList subform].Form.Filter = strFilter
Forms![InventoryList]![InventoryList subform].Form.FilterOn = True
Case 3 'Pending
'do something else
End Select