0

在 sinatra 中,我正在执行这段代码,其中包含 Hash 对象中的值:

@posts[0]["attachment"]["media"][0]["href"] # where @posts belongs to Koala::Facebook::API::GraphCollection class

在 sinatra 应用程序中工作正常,但是,使用循环:

@posts.each do |post|
      post["attachment"]["media"][0]["href"]
end

引发以下错误:

undefined method `[]' for nil:NilClass

在命令行上执行时显示的错误是:

> NoMethodError: undefined method `[]' for nil:NilClass     from
> (irb):12:in `block in irb_binding'    from (irb):11:in `each'     from
> (irb):11

我错过了什么?

4

0 回答 0