从http响应对象Angular 6

时间:2018-08-23 11:08:58

标签: angular typescript

我一直在搜索,但是找不到适合我的答案。

我有一个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",
   …
}

如何在此结果中获取具体的值? 我需要循环吗?

1 个答案:

答案 0 :(得分:0)

您的obj应该是任何类型,然后您可以按以下方式访问它,

processResults(obj: any) {
  console.log(obj.authorizationToken); 
}