我正在从 Node.JS 查询一个数据库 我试图访问 CodeFile 中 FileContent 字段的内容,它返回一个 Javascript 对象:结果。
jsUpdateCon.query('SELECT FileContent FROM codeFile WHERE ID = ?',[msg[1]], function(err, result){
if (err) throw err;
console.log('Data received from DB:\n');
console.log(result);
});
控制台输出:[ RowDataPacket { FileContent: 'someContent' } ]
如果我尝试 console.log(result.RowDataPacket);
我明白了
控制台输出:undefined
如果我尝试 console.log(result.RowDataPacket.FileContent);
整个 Node 崩溃
类型错误:无法读取未定义的属性“FileContent”
我的最终目标是得到
控制台输出:someContent
使用 console.log(result.something.something) 时
我做错了什么?
最佳答案
看起来 result
是一个数组,尝试像这样访问它:
console.log(result[0].FileContent)
关于javascript - Node js mysql访问javascript对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35638695/