我正在尝试解析JSON以获得特定的行。我已经在谷歌上尝试了很多我能找到的不同的东西,这是我能找到的最接近的东西。
我想要读的是:
[{
"id": "pinkcoin",
"name": "PinkCoin",
"symbol": "PINK",
"rank": "321",
"price_usd": "0.0281999",
"price_btc": "0.00000165",
"24h_volume_usd": "195433.0",
"market_cap_usd": "10470475.0",
"available_supply": "371294750.0",
"total_supply": "388294750.0",
"max_supply": null,
"percent_change_1h": "5.48",
"percent_change_24h": "10.83",
"percent_change_7d": "-7.62",
"last_updated": "1513043947"
}]我正在试着把"price_usd“部分从这里拉出来……下面是我使用的代码:
var request = require('request');
request('https://api.coinmarketcap.com/v1/ticker/pinkcoin/', function (error, response, body) {
fs.readFile(body, 'utf8', function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
data = JSON.parse(data);
bot.sendMessage({
to: channelID,
message: data.price_usd
});
});
});但是当我触发这段代码时,我在控制台中得到了这样的结果:
Error: Error: ENAMETOOLONG: name too long, open '[{
"id": "pinkcoin",
"name": "PinkCoin",
"symbol": "PINK",
"rank": "319",
"price_usd": "0.0284066",
"price_btc": "0.00000166",
"24h_volume_usd": "195093.0",
"market_cap_usd": "10547221.0",
"available_supply": "371294750.0",
"total_supply": "388294750.0",
"max_supply": null,
"percent_change_1h": "6.15",
"percent_change_24h": "11.55",
"percent_change_7d": "-6.97",
"last_updated": "1513044245"
}]'我一直在寻找解决这个问题的方法,但是我一无所获。
https://stackoverflow.com/questions/47764371
复制相似问题