【发布时间】:2023-04-07 20:10:01
【问题描述】:
我们的 GET 请求返回以下响应:
{
"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"
}
问题在于 AngularJS 将其解析为以下对象。
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
我们需要“userRoles”来解析成一个 JavaScript 数组而不是一个字符串,如图所示。我们该怎么做?
【问题讨论】:
标签: javascript arrays json angularjs parsing