2016-10-20 55 views
0

我正在嘗試使用API​​中的數據。下面是代碼我有當前工作:在ruby中處理json響應

...connection info here 
webinars = response.parsed_response["webinars"] 

webinars.each do |w| 
    puts w 
end 

這讓我回一個數組,如:

{"uuid"=>"2342342==", "id"=>285433, "host_id"=>"3423", "topic"=>"Requirement Changes", "agenda"=>"", "status"=>0, "option_start_type"=>"video", "option_host_video"=>true, "option_panelist_video"=>true, "option_audio"=>"both", "option_enforce_login"=>false, "type"=>5, "start_time"=>"2016-10-24T14:00:00Z", "duration"=>90, "timezone"=>"America/New_York", "start_url"=>"blah.com", "join_url"=>"blam.com", "created_at"=>"2016-09-22T13:31:09Z"}, {"uuid"=>"2342343==", "id"=>285434, "host_id"=>"3423", "topic"=>"Requirement Changes", "agenda"=>"", "status"=>0, "option_start_type"=>"video", "option_host_video"=>true, "option_panelist_video"=>true, "option_audio"=>"both", "option_enforce_login"=>false, "type"=>5, "start_time"=>"2016-10-24T14:00:00Z", "duration"=>90, "timezone"=>"America/New_York", "start_url"=>"blah.com", "join_url"=>"blam.com", "created_at"=>"2016-09-22T13:31:09Z"}

我想訪問每個屬性的每個網絡研討會喜歡...

webinars = response.parsed_response["webinars"] 

webinars.each do |w| 
    puts w.id 
end 

我該如何處理這個問題才能調用這樣的屬性?

回答

1

你可以做的,而不是w["id"]w.id

如果你的地圖將被由{uuid: "2342342==", id: 285433, host_id: "3423"}你可以調用它w.id

+0

謝謝兄弟!我發誓我嘗試過! :) – Lumbee