Create a gist now

Instantly share code, notes, and snippets.

@fra3il /0.rb Secret
Last active Jan 15, 2016

What would you like to do?
[WP/1438] JSON 을 파싱하는 방법
require "net/http"
require "json"
uri = URI("https://api.spotify.com/v1/search?type=artist&q=tycho")
# get_response 를 이용하는 방법
response = Net::HTTP.get_response(uri)
puts response # <Net::HTTPOK:0x007fbe2b054880>
puts response.body # String
puts JSON.parse(response.body) # Hash
# get 을 이용하는 방법
# response = Net::HTTP.get(uri)
# puts JSON.parse(response) # Hash
require "json"
json = File.read("./slack.json", :external_encoding => "UTF-8") # String
obj = JSON.parse(json) # Hash
obj.each do |key, value|
if key.eql? "results" # Array
value.each do |user|
puts "slack_id : #{user["slack_id"]}, name : #{user["name"]}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment