Extracting values from a hash

北城余情 提交于 2019-12-02 02:33:58

Try the following:

#!/usr/bin/env ruby

require 'httparty'

(HOST, ID, VERSION) = ARGV

class MyApi
  include HTTParty
  format :json
end

response = MyApi.get("http://#{HOST}/v1/dc/manifest/#{ID}/#{VERSION}")

puts response.inspect

The addition of the format :json tells HTTParty to parse the response as JSON. Then you'll get a hash you can iterate over properly.

Try:

file['manifest']['files'].each do |item|
   puts item['url']
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!