我不了解 JavaScript,但我只需要使用它的一小部分。我有一個網址“http://my-url/api/auth/v1”,它為我生成以下 json 回應:
{
"token": {
"token": "token-result-here",
"result": null,
"resultCode": "0",
"requestId": "xx"
},
我需要一個腳本,它只回傳“令牌”的結果。例如,當我呼叫“token”時,它回傳:“token-result-here”。任何人都可以幫助我使用此代碼嗎?
uj5u.com熱心網友回復:
如果
var response = {
"token": {
"token": "token-result-here",
"result": null,
"resultCode": "0",
"requestId": "xx"
}};
然后使用response.token.token訪問“token-result-here”
uj5u.com熱心網友回復:
您可以將 api 的請求保存到一個變數中,比如“apiResponse”,您可以這樣做:
//parse the JSON
JSON.parse(apiResponse);
//access the JSON
let token = apiResponse.token.token;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/358989.html
標籤:javascript json 网址
上一篇:http服務器回應異步函式的輸出
下一篇:正則運算式提取每個字母數字模式
