我有一个javascript /questions/tagged/javascriptarray:
{
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "Admin",
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "admin",
"nbf": 1512187433,
"exp": 1512187453,
"iss": "SuperAwesomeTokenServer",
"aud": "http://localhost:3000/"
}
第一个关键是"http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
其值为“Admin”。
我想访问此密钥,但在使用密钥名称时遇到问题,因为它是一个 href 而不是单个名称。
我将如何访问该值"Admin"
?我想用说myArray.role
等等,但角色名称位于很长的末尾href
带有多个斜杠等
我想知道访问它的最佳方式,但在 StackOverflow 保存拆分上找不到任何内容。如果能根据键名来访问就好了。
您可以采用以下方法:
var obj = {
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "Admin",
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "admin",
"nbf": 1512187433,
"exp": 1512187453,
"iss": "SuperAwesomeTokenServer",
"aud": "http://localhost:3000/"
}
console.log(obj["http://schemas.microsoft.com/ws/2008/06/identity/claims/role"]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)