Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从json Rails中选择特定日期数据_Ruby On Rails_Json_Ruby On Rails 3.2 - Fatal编程技术网

Ruby on rails 从json Rails中选择特定日期数据

Ruby on rails 从json Rails中选择特定日期数据,ruby-on-rails,json,ruby-on-rails-3.2,Ruby On Rails,Json,Ruby On Rails 3.2,我试图从解析的json系列中只选择Date.today+1.day的结果,但我对如何最好地实现这一点感到困惑 json的格式为: {"status": "ok", "data": {"temperatures": [["2014-09-16 07:00", 14.4], ["2014-09-16 08:00", 17.6], ["2014-09-16 09:00", 20.5], ["2014-09-16 10:00", 23.0], ["2014-09-16 11:00", 24.8], ["

我试图从解析的json系列中只选择Date.today+1.day的结果,但我对如何最好地实现这一点感到困惑

json的格式为:

{"status": "ok", "data": {"temperatures": [["2014-09-16 07:00", 14.4], ["2014-09-16 08:00", 17.6], ["2014-09-16 09:00", 20.5], ["2014-09-16 10:00", 23.0], ["2014-09-16 11:00", 24.8], ["2014-09-16 12:00", 26.4]]}}
控制器

dates = []
temps = []

@forecast['data']['temperatures'].each do |data|
 dates << data[0]
 temps << data[1]
end

dates.flatten.each do |d|
 dates << DateTime.parse(d).strftime("%d %b - %H:%M")
end

@results = dates.map {|f| [Date.today + 1.day(f), temps]}
dates=[]
temps=[]
@预测['data']['temperatures']|

日期如果要选择日期大于一天的数据,则:

@forecast['data']['temperatures'].select{|temp| temp[0].to_date > 1.day.from_now.to_date }
否则,如果要选择日期大于或等于从现在起一天的数据:

@forecast['data']['temperatures'].select{|temp| temp[0].to_date >= 1.day.from_now.to_date }