Ruby on rails 不通过获取数据将字符串隐式转换为整数
我正试图从api中获取数据 但我收到了错误: 不将字符串隐式转换为整数Ruby on rails 不通过获取数据将字符串隐式转换为整数,ruby-on-rails,each,Ruby On Rails,Each,我正试图从api中获取数据 但我收到了错误: 不将字符串隐式转换为整数 require 'rest-client' class Cmc url = 'https://api.coinmarketcap.com/v2/listings/' response = RestClient.get(url) @jsonData = JSON.parse(response) end coins = Cmc.new coins.listings.each do |dat
require 'rest-client'
class Cmc
url = 'https://api.coinmarketcap.com/v2/listings/'
response = RestClient.get(url)
@jsonData = JSON.parse(response)
end
coins = Cmc.new
coins.listings.each do |data|
puts "nrcoin: #{data['id']} |
namecoin: #{data['name']} |
symbolcoin: #{data['symbol']} |
slugcoin: #{data['website_slug']}"
end
你的编码不正确。我修改了你的代码。请运行这个。我希望它能起作用
# You have to install bellow gems to your local machine
# gem install rest-client
# gem install json
require 'rest-client'
require 'json'
class Cmc
def self.listings
url = 'https://api.coinmarketcap.com/v2/listings/'
response = RestClient.get(url)
JSON.parse(response)
end
end
coins = Cmc.listings
coins["data"].each do |data|
puts "nrcoin: #{data['id']} |
namecoin: #{data['name']} |
symbolcoin: #{data['symbol']} |
slugcoin: #{data['website_slug']}"
end
你的编码不正确。我修改了你的代码。请运行这个。我希望它能起作用
# You have to install bellow gems to your local machine
# gem install rest-client
# gem install json
require 'rest-client'
require 'json'
class Cmc
def self.listings
url = 'https://api.coinmarketcap.com/v2/listings/'
response = RestClient.get(url)
JSON.parse(response)
end
end
coins = Cmc.listings
coins["data"].each do |data|
puts "nrcoin: #{data['id']} |
namecoin: #{data['name']} |
symbolcoin: #{data['symbol']} |
slugcoin: #{data['website_slug']}"
end
有效:)谢谢。我不知道这是关于“数据”的。下一次很酷:)有效:)谢谢。我不知道这是关于“数据”的。下次再酷:)