我有一個json
輸出值返回未定義的問題。返回未定義值的JSON
JSON:
[ { ID: 2, user: 'ngx.daniel', password: 'password', admin: 'F' } ]
CODE:
console.log(res);
res = JSON.stringify(res);
console.log(res);
var user = {};
user.user = res.user;
user.password = res.password;
user.admin = res.admin;
console.log(user);
OUTPUT:
[ RowDataPacket { ID: 2, user: 'ngx.daniel', password: 'password', admin: 'F' } ]
[ { ID: 2, user: 'ngx.daniel', password: 'password', admin: 'F' } ]
{ user: undefined, password: undefined, admin: undefined }
'JSON.stringify'返回一個字符串。你爲什麼期望一個字符串擁有'user'屬性? – SLaks
@turbopipp:這沒有什麼區別。 – SLaks
JSON喜歡對象中的字符串,從我記得 – turbopipp