从 object/array 获取价值
Get value from object/array
我只需要在 JS 的变量中获取令牌。
{
"user": {
"id": "string",
"nickName": "string",
"score": 0,
"rank": 0
},
"token": "string"
}
这是我保存在变量中的响应,但我只需要从令牌中获取“字符串”值
如果您已将此响应存储在变量中,例如:
let response = {
"user": {
"id": "string",
"nickName": "string",
"score": 0,
"rank": 0
},
"token": "string"
}
您可以像这样从“令牌”中提取值属性
let tokenFromObject = response.token
或
let tokenFromObject = response["token"]
或
let { token } = response
你应该能够获取你得到这个 json 的变量并执行此操作:
let a = {"user":{},"token": "string"}; // this is what you got
console.log(a["token"]) // a["token"] will give you "string"
我只需要在 JS 的变量中获取令牌。
{
"user": {
"id": "string",
"nickName": "string",
"score": 0,
"rank": 0
},
"token": "string"
}
这是我保存在变量中的响应,但我只需要从令牌中获取“字符串”值
如果您已将此响应存储在变量中,例如:
let response = {
"user": {
"id": "string",
"nickName": "string",
"score": 0,
"rank": 0
},
"token": "string"
}
您可以像这样从“令牌”中提取值属性
let tokenFromObject = response.token
或
let tokenFromObject = response["token"]
或
let { token } = response
你应该能够获取你得到这个 json 的变量并执行此操作:
let a = {"user":{},"token": "string"}; // this is what you got
console.log(a["token"]) // a["token"] will give you "string"