【问题标题】:how to read json array without keys in typescript?如何在打字稿中读取没有键的json数组?
【发布时间】:2016-08-31 09:46:35
【问题描述】:

示例 JSON 数据:Complex Github API

来自 github api 的片段。

现在我想使用 typescript 列出“full_name”、“owner.login”。

【问题讨论】:

  • 你想要这个吗? var myArray = []; var obj = null; for(var i=0;i<jsonData.length;i++){ obj = {full_name: jsonData[i].full_name, owner_login: jsonData[i].owner.login; myArray.push(obj); }

标签: angular typescript1.8


【解决方案1】:

您可以在 JSON 数组上使用 map 函数,如下所示。

   let jsonResult = 'result from api call';
   let result = jsonResult.map(res => {
     return {
       full_name : res.full_name,
       owner_login: res.owner.login
     }
   })

result 将拥有该列表。

希望这会有所帮助!

【讨论】:

  • 不!实际上,我遇到的错误很少: res:Respone 的 full_name 属性不存在
猜你喜欢
  • 2020-12-04
  • 2018-01-28
  • 2018-12-17
  • 1970-01-01
  • 2019-05-04
  • 2023-04-02
  • 2021-08-22
  • 2020-06-12
  • 2017-06-16
相关资源
最近更新 更多