[英]How to get data from JSON Nodejs?
Code:代码:
var email = req.body.email
var sql = 'Select password FROM user where email = ' + mysql.escape(email)
con.query(sql, (err, rows, fields) => {
if (!err) {
res.send(rows)
var result = Object.values(JSON.parse(JSON.stringify(rows)))
console.log(result)
} else console.log(err)
})
Here, When I print the 'result' variable I can get output like below在这里,当我打印“结果”变量时,我可以得到 output 如下所示
[{ password: '123' }]
How I get password value to another variable (Example: x=123)如何获取另一个变量的密码值(例如:x=123)
Your password is stored as an object in the first cell of an array, therefore:您的密码作为 object 存储在数组的第一个单元格中,因此:
var result = [{ password: '123' }]; var x = result[0].password; //Get the password value of the object in the first cell of the array console.log('Result = ' + JSON.stringify(result)); console.log('x = ' + x);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.