JQuery:从结果对象数组中获取值

时间:2015-06-05 08:10:06

标签: javascript jquery

作为函数的结果我得到一个Javascript对象。在里面有一个名为accessToken的键的值。

   {
    "error": false,
        "data": {
        "key": {
            "validityTime": 3600,
                "consumerKey": "Z0jCb3WElmmKMvegklIAaqIfXWga",
                "tokenDetails":
                "{\"scopes\":[Ljava.lang.String;@862cb97,\"tokenState\":null}",
                "accessToken": "325d7b8b36d5a3e1965ea6b07dd3cda2",
                "appDetails":
                "{\"username\":
                    \"admin\",
                    \"redirect_uris\":
                        \"\",\"validityPeriod\":\"3600\",\"tokenScope\":[Ljava.lang.String;@a32ba44,\"client_name\":\"admin_LastWish343434_SANDBOX\",\"grant_types\":null}",
            "tokenScope": ["am_application_scope", "default"],
            "keyState": "APPROVED",
            "consumerSecret": "9R9xWbEvaEN24aRNd8KN5qyHqjMa",
            "enableRegenarate": true,
            "accessallowdomains": "ALL"
        }
    }
}

我想要的是在警报中显示访问令牌。

我试过以下。但它不会在警告框中打印该值。

 window.alert(JSON.stringify(key.tokenDetails.accessToken));

我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:0)

我可以通过调用警报功能解决问题,如下所示。

    var result = {
    "error": false,
        "data": {
        "key": {
            "validityTime": 3600,
                "consumerKey": "Z0jCb3WElmmKMvegklIAaqIfXWga",
                "tokenDetails":
                "{\"scopes\":[Ljava.lang.String;@862cb97,\"tokenState\":null}",
                "accessToken": "325d7b8b36d5a3e1965ea6b07dd3cda2",
                "appDetails":
                "{\"username\":
                    \"admin\",
                    \"redirect_uris\":
                        \"\",\"validityPeriod\":\"3600\",\"tokenScope\":[Ljava.lang.String;@a32ba44,\"client_name\":\"admin_LastWish343434_SANDBOX\",\"grant_types\":null}",
            "tokenScope": ["am_application_scope", "default"],
            "keyState": "APPROVED",
            "consumerSecret": "9R9xWbEvaEN24aRNd8KN5qyHqjMa",
            "enableRegenarate": true,
            "accessallowdomains": "ALL"
        }
    }
}

window.alert(result.data.key.accessToken);

成功打印了accessToken