我正在尝试获取令牌的价值但我收到错误ERROR TypeError: Cannot read property 'token' of undefined
//Below code gives the output shown below with black color text
data.text()
// I am interested in fetching token value which is nested inside success keyword, below code fails to get the token
var abc = data.text();
abc['success'].token
答案 0 :(得分:2)
let abc = JSON.parse(data.text());
答案 1 :(得分:1)
var abc = (JSON.parse(data._body)).success.token;
答案 2 :(得分:0)
以下代码用于阅读JWT表单js
function parseJwt (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace('-', '+').replace('_', '/');
return JSON.parse(window.atob(base64));
};