我是 Rails 新手,无法弄清楚如何遍历这些数据。这是集成 etsy API 的 gem 的输出。它看起来像一组哈希数组,也许吧?
output=[#<Etsy::Listing:0x5551ba8 @result={"listing_id"=>182661496, "title"=>"Edible Butterflies in Coral", "quantity"=>1, "price"=>"12.50", "ending_tsz"=>1405362199, "shipping_template_id"=>nil, "MainImage"=>{"url_75x75"=>"https://img1.etsystatic.com/036/0/8545731/il_75x75.576542775_ibud.jpg"}}, @token="token", @secret="secret">,
#<Etsy::Listing:0x5551bc0 @result={"listing_id"=>182671909, "title"=>"Marshmallow Sampler Pack", "quantity"=>3, "price"=>"9.50", "ending_tsz"=>1405362468, "shipping_template_id"=>1680751676, "MainImage"=>{"url_75x75"=>"https://img1.etsystatic.com/021/0/8545731/il_75x75.576544537_n2zo.jpg"}}, @token="token", @secret="secret">,
#<Etsy::Listing:0x5551bf0 @result={"listing_id"=>182663346, "title"=>"Gourmet popcorn and seasoning kit", "quantity"=>15, "price"=>"26.95", "ending_tsz"=>1405363087, "shipping_template_id"=>nil, "MainImage"=>{"url_75x75"=>"https://img0.etsystatic.com/026/0/8545731/il_75x75.576428850_r1mv.jpg"}}, @token="token", @secret">,
#<Etsy::Listing:0x5551c08 @result={"listing_id"=>189414412, "title"=>"Sailor Tote Bag", "quantity"=>45, "price"=>"50.00", "ending_tsz"=>1410586221, "shipping_template_id"=>1024284528, "MainImage"=>{"url_75x75"=>"https://img0.etsystatic.com/039/0/8545731/il_75x75.576443100_slse.jpg"}}, @token="token", @secret="secret">]
我尝试过的任何方法似乎都不起作用。将其视为数组适用于某些事情,例如: output.length 正确返回4。但是 output[0] 返回<Etsy::Listing:0x5483418>没有任何其他数据。我真正需要的只是@result={} 中包含的内容。想法?谢谢!