#!/usr/local/bin/ruby require 'net/http' require 'uri' require 'json' #url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=011000" #url = "http://www.land.mlit.go.jp/webland/api/TradeListSearch?from=20101&to=20134&station=02590" url = "http://www.land.mlit.go.jp/webland/api/TradeListSearch?from=20101&to=20161&city=13421" uri = URI.parse(url) json = Net::HTTP.get(uri) result = JSON.parse(json) trade_data = [] (0..100).each do |i| # puts result.dig("data", i, "DistrictName") # puts result.dig("data", i, "PricePerUnit") if result.dig("data", i, "TradePrice").to_i <= 1000000 trade_data << result.dig("data", i)#, "DistrictName") # puts result.dig("data", i, "PricePerUnit") end end json_str = JSON.pretty_generate(trade_data) puts json_str =begin puts result.dig("pinpointLocations", 0, "name")#, "name") puts result.dig("forecasts", 0, "date") puts result.dig("forecasts", 0, "telop") puts result.dig("forecasts", 1, "date") puts result.dig("forecasts", 1, "telop") =end