15

哈希:

p: {:headline=>"Managing Director at Test company name", :pid=>"0tSsRvCR7r", :first_name=>"John", :last_name=>"Doe", :industry=>"Financial Services", :summary=>nil, :public_profile_url=>"http://www.linkedin.com/pub/john-doe/7a/78/606", :distance=>0}

尝试调用 p.pid 但收到错误:

EXCEPTION: undefined method `pid' for #<Hash:0x007fcf1b3a29f0> 

所有其他元素都可以正常访问。还尝试了该字段的不同名称,但无济于事。任何人都可以对此有所了解吗?真的希望它不是你盯着很久才意识到这是愚蠢的错误之一:/。

注意:我也尝试过 p['pid']。这也不起作用。Rails 相对较新。

4

1 回答 1

28

尝试这样的事情:

p = {:headline=>"Managing Director at Test company name", :pid=>"0tSsRvCR7r", :first_name=>"John",     :last_name=>"Doe", :industry=>"Financial Services", :summary=>nil,     :public_profile_url=>"http://www.linkedin.com/pub/john-doe/7a/78/606", :distance=>0}
puts p
puts p[:pid]

哈希文档

更多关于哈希

于 2013-08-19T14:38:22.947 回答