Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 不通过获取数据将字符串隐式转换为整数_Ruby On Rails_Each - Fatal编程技术网

Ruby on rails 不通过获取数据将字符串隐式转换为整数

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

我正试图从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 |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
有效:)谢谢。我不知道这是关于“数据”的。下一次很酷:)有效:)谢谢。我不知道这是关于“数据”的。下次再酷:)