【发布时间】:2012-04-07 11:16:58
【问题描述】:
从 LinkedIn API 我得到了这个哈希:
> #<LinkedIn::Mash all=[#<LinkedIn::Mash api_standard_profile_request=#<LinkedIn::Mash headers=#<LinkedIn::Mash
> all=[#<LinkedIn::Mash name="x-li-auth-token" value="name:_nNI">]
> total=1> url="http://api.linkedin.com/v1/people/asdasfga">
> first_name="first name" headline="job position"
> id="id of user" industry="industry"
> last_name="last name" location=#<LinkedIn::Mash
> country=#<LinkedIn::Mash code="en"> name="country">
> site_standard_profile_request=#<LinkedIn::Mash
> url="http://www.linkedin.com/profile?viewProfile=&key=key_number&authToken=_nNI&authType=name&trk=api*a_12346*s_12346*">>]
> total=1>
我尝试获取first_name、url 和country 已经很长时间了,但我仍然无法解析它。
谁能帮帮我?
提前致谢
编辑次尝试:
linkedin.connections.each do |item|
puts item
end
给予
total
1
all
#<LinkedIn::Mash api_standard_profile_request=#<LinkedIn::Mash headers=#<LinkedIn::Mash all=[#<LinkedIn::Mash name=...
当我尝试时
linkedin.connections.api_standard_profile_request.each do |item|
puts item
end
然后我得到了
undefined method `each' for nil:NilClass
【问题讨论】:
-
请查看更新后的帖子。我不知道如何进入
api_standard_profile_request哈希。 -
linkedin.connections是什么类型的对象?那是您在问题开头打印的对象吗? -
您可以调用
.to_hash将 Mash 转换为 Hash(如 params)。linkedin.to_hash
标签: ruby-on-rails ruby parsing hash linkedin