簡體   English   中英

從api調用中獲取特定數據

[英]Fetching A Particular data from a api call

我的js代碼是

    <script>       
    fetch('https://api.binance.com/api/v1/trades?symbol=BTCUSDT')
   .then(resi => resi.json())
   .then(data =>(console.log(data)));
    resi.send();
    </script>

從響應中可以得出以下之一:

[0…99]
0:
id:96874552
isBestMatch:true
isBuyerMaker:為true
價格:“ 3584.58000000”
數量:“ 0.00293100”
時間:1548506554914
原型 :對象

我有100個這樣的結果。 但是我只能從中獲取數量或價格並將其存儲在使用數組的變量中嗎?

是的,您可以使用map創建所需的新對象數組。

在您的情況下:

fetch('https://api.binance.com/api/v1/trades?symbol=BTCUSDT')
   .then(resi => resi.json())
   .then(data => data.map(item => Object({"qty":item.qty, "price":item.price}));
    resi.send();

然后, data將包含由100個qtyprice組成的商品組成的數組。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM