我想访问coinmarketcap结果的Rails:访问CoinmarketCap API
https://api.coinmarketcap.com/v1/ticker/?limit=3
这是结果。是一个哈希数组。有一种方法可以访问每个散列而不是数字(Array [0]),因为这些数字每天都在变化,但像Array [:id ='bitcoin']或类似的东西?
[
{
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "5751.67",
"price_btc": "1.0",
"24h_volume_usd": "1404240000.0",
"market_cap_usd": "95774433400.0",
"available_supply": "16651587.0",
"total_supply": "16651587.0",
"percent_change_1h": "0.14",
"percent_change_24h": "-1.5",
"percent_change_7d": "-4.24",
"last_updated": "1509240553"
},
{
"id": "ethereum",
"name": "Ethereum",
"symbol": "ETH",
"rank": "2",
"price_usd": "298.258",
"price_btc": "0.0519853",
"24h_volume_usd": "267318000.0",
"market_cap_usd": "28449497378.0",
"available_supply": "95385530.0",
"total_supply": "95385530.0",
"percent_change_1h": "0.58",
"percent_change_24h": "0.13",
"percent_change_7d": "-0.74",
"last_updated": "1509240550"
},
{
"id": "ripple",
"name": "Ripple",
"symbol": "XRP",
"rank": "3",
"price_usd": "0.20106",
"price_btc": "0.00003504",
"24h_volume_usd": "28961600.0",
"market_cap_usd": "7747151216.0",
"available_supply": "38531538922.0",
"total_supply": "99993667738.0",
"percent_change_1h": "-0.21",
"percent_change_24h": "-0.97",
"percent_change_7d": "-2.36",
"last_updated": "1509240541"
}
]
也许水木清华这样https://stackoverflow.com/questions/2244915/how-do-i-search-within-an-array-of- hash-values-in-ruby –