我的回复是以下格式,
{
"access_token": "eWcWLctGW-_NgGVAmFbO9l-nt3yztFzlZCLLlilI9mGDcM5q8d0kQw0uzvFOoXynHcb-MuPVJGTGkSkBhrr69_-aN1r5j9zB4fCl4u4aqOQ-scNI36xgHeGYpXky60drIBpMI83FGqd9pMjL4GWXjFHq61nhJ6xkGj1u1r9a5u6EJrB1lfjNhljzC_j65xaqxtubQ4AglKFO2ib-levpvnd_bEU-QGQrtvS2QbaXhb_hlnX8czo61Gn_OQyBVk7HbN1SozxIPe3RBvf5AiCAouDMz1WMHy9ybVFy8SnoNIgszjo7Ev2IEWS9aFb87u6bvoJvSVJv7s3z-2GUvG2kwfOk2sUWrmq0QeIJJrYwdKQfs3T8HrK2MNKSGteJ04-O",
"token_type": "bearer",
"expires_in": 1799,
"refresh_token": "f1005c7fd74247069dbdb078ee379410",
"as:client_id": "438dc832-33c7-413b-9c71-d0b98a196e6a",
"userName": "master",
".issued": "Fri, 20 Jan 2017 14:30:09 GMT",
".expires": "Fri, 20 Jan 2017 15:00:09 GMT"
}
我不知道如何访问.issued
,.expires
和as:client_id
我正在使用angular并传递用户名,密码和company_id,并以上述格式获取响应.
dataService.getAuthToken($scope.username, $scope.password, $scope.company_password).then(function (response) {
//response data here
});
我可以token_type
通过使用response.data.access_token
但不确定如何访问来轻松获取,access_token .issued
,.expires
和as:client_id
您可以通过索引器语法访问JavaScript中对象的每个属性,就像它是一个映射一样(因为一个对象是javascript中的一个映射):
var issued = response.data[".issued"]; var expires = response.data[".expires"]; var asClient_id= response.data["as:client_id"];
请参阅此链接:http://www.w3schools.com/js/js_objects.asp
访问对象属性
您可以通过两种方式访问对象属性:objectName.propertyName
或
objectName ["propertyName"]