0
嘗試使用Node.js/Javascript將對象轉換爲字符串時出現以下錯誤。使用Node.js將對象轉換爲字符串時出現類型錯誤
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at exports.userlogin (/opt/lampp/htdocs/FGDP/route/route.js:11:19)
at Layer.handle [as handle_request] (/opt/lampp/htdocs/FGDP/node_modules/express/lib/router/layer.js:95:5)
at next (/opt/lampp/htdocs/FGDP/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/opt/lampp/htdocs/FGDP/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/opt/lampp/htdocs/FGDP/node_modules/express/lib/router/layer.js:95:5)
at /opt/lampp/htdocs/FGDP/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/opt/lampp/htdocs/FGDP/node_modules/express/lib/router/index.js:330:12)
at next (/opt/lampp/htdocs/FGDP/node_modules/express/lib/router/index.js:271:10)
我在下面解釋我的代碼。
exports.userlogin=function(req,res){
var username=req.body.user_name;
var password=req.body.user_pass;
var ciphertext = CryptoJS.AES.encrypt(password, 'lexelPass');
var pass=JSON.stringify(ciphertext);
}
這裏我得到ciphertext
變量的數據類型爲對象,我需要它轉換成字符串。但在這裏我得到這種類型的錯誤。請幫我解決這個問題。
您是否控制並查看「ciphertext」的返回類型? 它是什麼類型? – ricky
我認爲這裏的'ciphertext'是一個'word-array'或'byte-array'而不是一個對象。首先進行必要的轉換。 – nashcheez
@ricky:它給出'object'類型。 – satya