你好,我在使用Fetch显示来自API的数据时遇到问题。
当我试图提取函数"0"时;Map((";Uncaught(在promise中(TypeError:globalInfo.map不是一个函数";
下面我正在粘贴代码。
fetch('https://coinpaprika1.p.rapidapi.com/global', target)
.then(response => response.json())
.then((globalInfo) => {
infos = globalInfo.map((info) => {
return {
mcap: market_cap_usd.info
volume: volume_24h_usd.info
}
})
})
对象{market_cap_ud:1020943415527,volume_24h_ud:69817864918,bitcoin_dominance_percentage:37.14,cryptocurrencies_number:8297,market_cap_ath_value:362984273801,market_cp_ath_date:quot;2021-10-27T07:40Z",volume_224h_ath_vvalue:2461621335224,volume_244h_ath_date:quot;2032-03-26T05:00Z",volume_44h_perment_from_ath:97.16,volume_24h _perment_to_ath:3425.78,…}bitcoin_dominance_percentage:37.14加密货币_编号:8297上次更新:1662299758market_cap_ath_date:"2021-10-27T07:40:00Z";market_cap_ath_value:3629384273801market_cap_change_24h:0.04市场_美元:1020943415527volume_24h_ath_date:";2022-03-26T03:05:00Z";volume_24h_ath_value:2461621335224容量24h_change_24h:26.74体积_24h_百分比_起始时间:-97.16体积_24h_perment_to_ath:3425.78第24卷美元:69817864918:对象{…}
你可以试试这个:
fetch('https://coinpaprika1.p.rapidapi.com/global', target)
.then(response => response.json())
.then((globalInfo) => {
return {
mcap: globalInfo.market_cap_usd
volume: globalInfo.volume_24h_usd
}
})
请确认这是否有效。