Node.js 如何读取带有 HTTP 地址元素的 JSON
Node.js how do you read a JSON with an element that is a HTTP address
好的,我 运行 遇到了一个问题。我正在使用 Auth0 在 App 元数据中创建具有不同权限(不仅仅是权限范围)的用户。当我解码令牌时,我得到这个 json:
{
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
如您所见,应用元数据位于元素“https://thetestgroup.com/app_metadata”中。通常我会在我的代码(auth.payload.iat)中做这样的事情来获得iat但是对于app_metadata它拒绝它因为:.是否有获取该数据的好方法?
好的,让我们谈谈 javascript(节点)和你的 json
Firefox 便签本 (Shift-F4)
var x = {
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
x['https://thetestgroup.com/app_metadata'].is_admin // hit run
/*
true
*/
node.js
~ $ node -v
v8.1.0
~ $ node
> var x = {
... "iss": "https://testing.auth0.com/",
... "sub": "auth0|58e7bae154941844b507eaf5",
... "aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
... "exp": 1497016797,
... "iat": 1496980797,
... "https://thetestgroup.com/app_metadata": {
..... "is_admin": true
..... }
... }
undefined
> x['https://thetestgroup.com/app_metadata'].is_admin
true
>
请提供一个 mcve 因为纯 JS 和 JSON 非常愉快地使用(奇怪的)键 - 正如所展示的那样。
好的,我 运行 遇到了一个问题。我正在使用 Auth0 在 App 元数据中创建具有不同权限(不仅仅是权限范围)的用户。当我解码令牌时,我得到这个 json:
{
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
如您所见,应用元数据位于元素“https://thetestgroup.com/app_metadata”中。通常我会在我的代码(auth.payload.iat)中做这样的事情来获得iat但是对于app_metadata它拒绝它因为:.是否有获取该数据的好方法?
好的,让我们谈谈 javascript(节点)和你的 json
Firefox 便签本 (Shift-F4)
var x = {
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
x['https://thetestgroup.com/app_metadata'].is_admin // hit run
/*
true
*/
node.js
~ $ node -v
v8.1.0
~ $ node
> var x = {
... "iss": "https://testing.auth0.com/",
... "sub": "auth0|58e7bae154941844b507eaf5",
... "aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
... "exp": 1497016797,
... "iat": 1496980797,
... "https://thetestgroup.com/app_metadata": {
..... "is_admin": true
..... }
... }
undefined
> x['https://thetestgroup.com/app_metadata'].is_admin
true
>
请提供一个 mcve 因为纯 JS 和 JSON 非常愉快地使用(奇怪的)键 - 正如所展示的那样。