-
-
Save fra3il/3ba31095d4514b8fa6e6 to your computer and use it in GitHub Desktop.
[WP/1438] JSON 을 파싱하는 방법
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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