尝试从RapidAPI提取的结果中获取数据

问题描述

我对Web编程非常陌生,需要帮助。

我正在使用Node.js通过RapidAPI获取数据 提取的结果以数组的形式向我返回了JSON解析格式。 但是,如果我要提供索引,它将返回字母,而不是我想要查看的项目。

下面是我要获取Apple结果的代码

const express = require('express');
const bodyParser = require('body-parser');
const http = require("https");

const app = express();
app.use(bodyParser.urlencoded({extended:true}));

app.get("/",function(request,response){
    response.sendFile(__dirname + "/index.html");
});

app.post("/",response){
const options = {
    "method": "get","hostname": "rapidapi.p.rapidapi.com","port": null,"path": "/income-statement/AAPL?apikey=demo","headers": {
        "x-rapidapi-key": "895157e459mshecb81dbe427f124p1fe70cjsn772a488898eb","x-rapidapi-host": "financial-modeling-prep.p.rapidapi.com","useQueryString": true
    }
};

const req = http.request(options,function (res) {
    const chunks = [];
    
    if (res.statusCode === 200) {
        console.log("Success");
    } else {
        console.log("Fail");
    }

    res.on("data",function (chunk) {
        console.log(chunk.toString('utf-8')[23]);
        chunks.push(chunk);
    });

    res.on("end",function () {
        const body = Buffer.concat(chunks); 

    });
});    
req.end();
});

“块”的日志结果:
[38个
0:{46项
“ date”:“ 2020-09-26”
“符号”:“ AAPL”
“ fillingDate”:“ 2020-10-30”
“ acceptedDate”:“ 2020-10-29 18:06:25”
“句号”:“ FY”
“现金和现金等价物”:38016000000
“短期投资”:52927000000
“ cashAndShortTermInvestments”:90943000000
“ netReceivables”:16120000000
“库存”:4061000000
“ otherCurrentAssets”:32589000000
“ totalCurrentAssets”:143713000000
“ propertyPlantEquipmentNet”:36766000000
“善意”:0
“ intangibleAssets”:0
“ goodwillAndIntangibleAssets”:0
“长期投资”:100887000000
“ taxAssets”:0
“ otherNonCurrentAssets”:42522000000
“ totalNonCurrentAssets”:180175000000
“ otherAssets”:90482000000
“总资产”:323888000000
“应付帐款”:42296000000
“ shortTermDebt”:8773000000
“ taxPayables”:0
“ deferredRevenue”:6643000000
“ otherCurrentLiabilities”:47680000000
“总当前负债”:105392000000
“ longTermdebt”:98667000000
“ deferredRevenueNonCurrent”:0
“ deferredTaxLiabilitiesNonCurrent”:0
“ otherNonCurrentLiabilities”:54490000000
“总非当前负债”:153157000000
“ otherLiabilities”:0
“总负债”:258549000000
“ commonStock”:16976763000
“保留收益”:14966000000
“ accumulatedOtherComprehensiveIncomeLoss”:-406000000
“其他股票所有者权益”:33802237000
“总股东权益”:65339000000
“负债总额和股东权益”:323888000000
“总投资额”:153814000000
“总债务”:107440000000
“ netDebt”:69424000000
链接”:“ https://www.sec.gov/Archives/edgar/data/320193/000032019320000096/0000320193-20-000096-index.htm”
“ finalLink”:“ https://www.sec.gov/Archives/edgar/data/320193/000032019320000096/aapl-20200926.htm”
},...]

问题:如果我特别想从响应中访问“ netDebt”之类的特定字段,我将如何访问它?

ex)chunck [0]返回类似“ l”的字母。我想我不太清楚它的结构。 我在想像块[0] [“ netDebt”]

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)