Я разобрал API JSON внешне, и теперь это хэш, как например:Iterate obect в поле зрения, JSON хэш
["statement", {"generated"=>"2015-01-11", "due"=>"2015-01-25", "period"=>{"from"=>"2015-01-26", "to"=>"2015-02-25"}}
Я использовал:
require 'json/pure'
require 'open-uri'
def index
content = open("MY_URL").read
@hash = JSON.parse content
render @hash
end
, и это дает мне всю хэш выход на представлении с помощью:
<% @hash.each do |hash| %>
<%= hash %>
<% end %>
Так позволяет сказать, что я хотел печатать генерироваться за счет и период, отдельно, как бы я это сделать. Я так близко, что знаю это.
массив:
["statement", {"generated"=>"2015-01-11", "due"=>"2015-01-25", "period"=>{"from"=>"2015-01-26", "to"=>"2015-02-25"}}] ["total", 136.03] ["package", {"subscriptions"=>[{"type"=>"tv", "name"=>"Variety with Movies", "cost"=>50.0}, {"type"=>"talk", "name"=>"Talk Anytime", "cost"=>5.0}, {"type"=>"broadband", "name"=>"Fibre Unlimited", "cost"=>16.4}], "total"=>71.4}] ["callCharges", {"calls"=>[{"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"07716393769", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}, {"called"=>"02074351359", "duration"=>"00:23:03", "cost"=>2.13}], "total"=>59.64}] ["Store", {"rentals"=>[{"title"=>"50 Shades of Grey", "cost"=>4.99}], "buyAndKeep"=>[{"title"=>"That's what she said", "cost"=>9.99}, {"title"=>"Broke back mountain", "cost"=>9.99}], "total"=>24.97}] [:prefixes, ["tasks", "application"]] [:template, "index"]
все делает для меня смысл, однако я получаю неопределенный метод ошибки '[]» для ноля: NilClass – Mohammed
вы можете копировать и вставлять строка кода, которая породила ошибку? –
<% = @hash_values ['generated']%> Трассировка приложения: app/views/tasks/index.html.erb: 3: in 'block in _app_views_tasks_index_html_erb___299787190_93358320 ' app/views/tasks/index.html.erb: 1 : in 'each ' app/views/tasks/index.html.erb: 1: in_ _app_views_tasks_index_html_erb___299787190_93358320' app/controllers/tasks_controller.rb: 13: в' index ' – Mohammed