[英]Get data from the response
I have a response which is of the below format, 我有以下格式的回复,
{ "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" }
I'm not sure how to access .issued
, .expires
and as:client_id
我不确定如何访问
.issued
, .expires
和as:client_id
I'm using angular and passing username, password and company_id and getting the response in the above format. 我正在使用angular并传递用户名,密码和company_id,并以上述格式获取响应。
dataService.getAuthToken($scope.username, $scope.password, $scope.company_password).then(function (response) { //response data here });
I can easily get token_type
, access_token by just using response.data.access_token
but not sure how to access .issued
, .expires
and as:client_id
我可以通过仅使用
response.data.access_token
轻松获得token_type
,access_token,但不确定如何访问.issued
, .expires
和as:client_id
You can access every property of an object in JavaScript by the indexer syntax, like if it was a map (because an object is a map in javascript): 您可以通过索引器语法访问JavaScript中对象的每个属性,就像它是一个映射一样(因为对象是javascript中的映射):
var issued = response.data[".issued"];
var expires = response.data[".expires"];
var asClient_id= response.data["as:client_id"];
See this link: http://www.w3schools.com/js/js_objects.asp 看到此链接: http : //www.w3schools.com/js/js_objects.asp
Accessing Object Properties
访问对象属性
You can access object properties in two ways:您可以通过两种方式访问对象属性:
objectName.propertyName
objectName.propertyName
or要么
objectName["propertyName"]对象名[ “PROPERTYNAME”]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.