我一直在搜索,但是找不到适合我的答案。
我有一个http
邮寄服务,我可以获得
以对象格式回答,我的代码如下:
data.subscribe(data => {
let results;
this.results = data;
this.processResults(this.results);
}
processResults(obj: Object) {
console.log(obj);
// what I want to do is retrieve the value in resultCodeConstant, I //tried functions like filter and find but always get an error, saying it's //does not exist on type Object
// let item = obj.filter(element.name == 'resultCodeConstant')
}
我来自http订阅的响应看起来像obj的这个值:
{
authorizationToken: "qTYLf6f...",
secretQuestionId: null,
secretQuestionSentence: null,
resultCodeConstant: "AUTHORIZED",
userAccountState: "active",
…
}
如何在此结果中获取具体的值? 我需要循环吗?
答案 0 :(得分:0)
您的obj应该是任何类型,然后您可以按以下方式访问它,
processResults(obj: any) {
console.log(obj.authorizationToken);
}