public
Last active

Example For Downloading and Parsing JSON (Ruby)

  • Download Gist
Ruby Download Parse JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
require "rubygems"
require "json"
require "net/http"
require "uri"
 
uri = URI.parse("http://api.sejmometr.pl/posiedzenia/BZfWZ/projekty")
 
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
 
response = http.request(request)
 
if response.code == "200"
result = JSON.parse(response.body)
result.each do |doc|
puts doc["id"] #reference properties like this
puts doc # this is the result in object form
puts ""
puts ""
end
else
puts "ERROR!!!"
end
Ruby :: Download & Parse JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
require "rubygems"
require "json"
require "net/http"
require "uri"
 
uri = URI.parse("http://api.sejmometr.pl/posiedzenia/BZfWZ/projekty")
 
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
 
response = http.request(request)
 
if response.code == "200"
result = JSON.parse(response.body)
result.each do |doc|
puts doc["id"] #reference properties like this
puts doc # this is the result in object form
puts ""
puts ""
end
else
puts "ERROR!!!"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.