TypeScript 迭代 JSON 并放置 JSON 个元素

TypeScript Iterate JSON and put JSON elements

我是 TypeScript 的新手,但我想做的很简单,但文档似乎没有涵盖 JSON 的迭代。我想要做的是遍历 JSON 响应数组并将 JSON 对象放入每个 JSON 元素中。这是我正在使用的代码,WebStorm 中的 TypeScript 评估器告诉我 speakerElement 是一个字符串而不是 JSON 所以我不能使用 put 函数。

return new Promise(resolve => {
   this.http.get('http://.staging.wpengine.com/wp-json/wp/v2/cr3ativspeaker')
   .map(res => res.json())
.subscribe(data => {
  console.log("the speaker data is : ", data);
  console.log("the speaker data is : ", JSON.stringify(data));
  //get each speakers image and append it to their data
  for(let speakerElement in <JSON>data) {

    this.http.get('http://.staging.wpengine.com/wp-json/wp/v2/cr3ativspeaker')
      .map(res => res.json())
      .subscribe(response => {

       speakerElement.put("media_details", response.media_details);

      });

  }

  this.data = data;
  resolve(this.data);
});
});

首先感谢大家的建议。我找到了需要很小改动的答案。我在 For Loop 中使用 in。我需要使用 of。正确的代码是

 for(let speakerElement of data) {
            console.log("Speaker element",speakerElement);// element is JSON 

          }