【发布时间】:2019-09-27 03:57:58
【问题描述】:
您好,我正在尝试从 JSON 访问特定密钥。我正在使用 node.js 和 Angular 7 我得到的 JSON 是 stringfy,它来自一个 API。
这是我得到的 JSON
"search": {
"entry": [
{
"dn": "uid=080030781,c=mx,ou=s,o=i.com",
"attribute": [
{ "name": "mail", "value": ["CAMILA.CAMPOS.TELLEZ@mail.com", "MX08@mail.com"] }]
}
],
"return": {
"code": 0,
"message": "Success",
"count": 1
}
}
}
我需要访问键“value”,因为我需要获取值“camila.campos.tellez@mail.com”。 我从一个名为 app.js 的 node.js 文件中声明的 API 获取 JSON,然后我使用这个 service.ts 文件捕获它的响应
getApproverMail(name) {
console.log('entered to rootservice');
return this.http.get(this.baseUrl + '/costing/operations?name=' + name);
}
最后我可以通过带有此代码的 component.ts 文件访问它
findApproverMail() {
this.rootService.getApproverMail(this.aproverName).subscribe((res) => {
this.email = res;
console.log('Test: ' + res);
});
}
浏览器控制台会打印我向您展示的 JSON。但是我怎样才能只访问邮件的价值呢? P.D 我只需要邮件,因为收到邮件后,网站需要向该方向发送电子邮件
【问题讨论】:
标签: node.js angular api angular7