Reputation: 141462
Our GET request returns the following response:
{
"access_token": "pi7ID4bsZIC9yN ... 76gnblw",
"token_type": "bearer",
"expires_in": 1209599,
"userName": "super0",
"userRoles": "["member", "admin"]",
".issued": "Tue, 04 Feb 2014 05:07:51 GMT",
".expires": "Tue, 18 Feb 2014 05:07:51 GMT"
}
The problem is that AngularJS parses it into the following object.
data: Object
.expires: "Tue, 18 Feb 2014 05:07:51 GMT"
.issued: "Tue, 04 Feb 2014 05:07:51 GMT"
access_token: "pi7ID4bsZIC9yN ... 76gnblw"
expires_in: 1209599
token_type: "bearer"
userName: "super0"
userRoles: "["member", "admin"]"
__proto__: Object
We need "userRoles" to parse into a JavaScript array not a string as shown. How can we do this?
Upvotes: 0
Views: 290
Reputation: 60580
That's not valid JSON. The array should not be quoted.
It should look like this instead:
{
"access_token": "pi7ID4bsZIC9yN ... 76gnblw",
"token_type": "bearer",
"expires_in": 1209599,
"userName": "super0",
"userRoles": ["member", "admin"],
".issued": "Tue, 04 Feb 2014 05:07:51 GMT",
".expires": "Tue, 18 Feb 2014 05:07:51 GMT"
}
Upvotes: 1