【发布时间】:2019-08-26 05:43:59
【问题描述】:
我收到的响应是 JSON 数组,格式如下:
{
"response": {
"refreshToken": "sometoken",
"token": "sometoken",
"user": {
"active": 12,
"id": 5,
"name": "abc",
"password": "def"
}
}
}
现在我想在 typescript 中访问名称和密码。
this._scaffolder.AuthGuard.authenticate(JSON.stringify(requestBody))
.subscribe(response => {
this._logger.info(response);
if (response && response.valid) {
console.log(response.user.name);
this._scaffolder.Cluster.API.silentlyNavigate('model');
} else {
this.areCredsInvalid = true;
}
});
我已经尝试过这个,我尝试访问名称字段。
但我看到一个错误: 类型响应中不存在属性用户。 响应对象如下图,其中user是UserModel的对象
response: {
valid: boolean;
response: PlatformServiceProxy.ErrorResponse | {
token: string;
refreshToken: string;
user: PlatformServiceProxy.UserModel;
};
【问题讨论】:
-
它在控制台中为
this._logger.info(response);显示什么? -
authenticate函数长什么样子?
标签: json angular typescript nested-attributes