【发布时间】:2021-01-23 07:59:53
【问题描述】:
这是一个使用 api 和参数获取 BTC 价格的简单代码。 当我尝试这段代码时,我得到了未定义,但如果我替换了“data.rates.crypto;”通过“data.rates.BTC”我得到一个 尽管加密货币的价值,但当前价格的价值是相同的“BTC”
app.post("/", function(req, res) {
var crypto = req.body.crypto; //this line gives BTC
var baseUrl = "http://api.coinlayer.com/api/live?access_key=lablabalab&symbols=";
var finalUrl = baseUrl + crypto; //no problem here by passing the parameter whics is BTC
request(finalUrl, function(error, response, body) {
var data = JSON.parse(body);
var price = data.rates.crypto; //here is the problem
res.write("<h1>Cuurent Price From " + crypto + " To USD is " + price + "</h1>");
res.send();
});
【问题讨论】: