我已经拖延了几个小时,收效甚微。
我有以下字符串片段:
{
"S:Envelope": ,
"S:Body": [{
"ns2:createTokenResponse": [{
"$": {
"xmlns:ns2": "http://IdentitySearch.nimc/"
},
"return": [{
"loginObject": [{
"timestamp": ["201912220556"],
"token": "rO0ABXNyABB1ZGYuTG9naW5NZXNzYWdlyuR/FrgVt2ECABVaAA1hdXRoZW50aWNhdGV
...
给定Node中的上述字符串,如何访问时间戳或令牌的值?
感谢您的智慧。
最佳答案
// if you have a string use a = JSON.parse(a);
let a = {
"S:Envelope": "",
"S:Body": [{
"ns2:createTokenResponse": [{
"$": {
"xmlns:ns2": "http://IdentitySearch.nimc/"
},
"return": [{
"loginObject": [{
"timestamp": ["201912220556"],
"token": "rO0ABXNyABB1ZGYuTG9naW5NZXNzYWdlyuR/FrgVt2ECABVaAA1hdXRoZW50aWNhdGV"
}]
}]
}]
}]
};
let timestamp = a["S:Body"][0]["ns2:createTokenResponse"][0]["return"][0]["loginObject"][0]["timestamp"][0];
let token = a["S:Body"][0]["ns2:createTokenResponse"][0]["return"][0]["loginObject"][0]["token"];
console.log(timestamp);
console.log(token);