我正在使用 JSON 来解析字符串。给定艺术家姓名,我使用 echonest API 打印该艺术家的五首歌曲:
require 'net/http'
require 'rubygems'
require 'json'
puts "Enter an artists name:"
artist_name = gets.chomp
file =open(parsed)
url = URI.parse("http://developer.echonest.com/api/v4/artist/songs? api_key=RYOXFCWIBV9IM0XCU&name=#{artist_name}&format=json&start=0&results=5")
res = Net::HTTP.get_response(url)
#puts res.body
parsed = JSON.parse(res.body)
parsed{'songs'}.each do |song|
puts song{'title'}
end