我正在尝试解析来自 LinkedIn 的哈希,并遇到错误
这是我要解析的哈希(从 Mash 转换而来):
#<LinkedIn::Mash first_name="John" headline="Recruiter" id="xxxxxxxx" industry="Telecommunications" last_name="Smith" location=#<LinkedIn::Mash country=#<LinkedIn::Mash code="us"> name="Greater Philadelphia Area"> positions=#<LinkedIn::Mash all=[#<LinkedIn::Mash company=#<LinkedIn::Mash id=2325416 industry="Staffing and Recruiting" name="Amazing Associates, Inc" size="1-10 employees" type="Privately Held"> id=9999999 is_current=true start_date=#<LinkedIn::Mash month=6 year=2010> summary="" title="Corporate Recruiter">] total=1> public_profile_url="http://www.linkedin.com/pub/greatguyjohn">
这是我的代码:
<% if !connection["positions"].nil? %>
<% connection["positions"].each do |positions| %>
<% if !positions["all"].nil? %>
<% positions["all"].each do |company| %>
<%= company %>
<% end %>
<% end %>
<% end %>
<% end %>
这是错误:
can't convert String into Integer
Extracted source (around line #15):
12: <% if !connection["positions"].nil? %>
13: <% connection["positions"].each do |positions| %>
14: <% if !positions["all"].nil? %>
15: <% positions["all"].each do |company| %>
16: <%= company %>
17: <% end %>
问题似乎是从 ["positions"] 哈希中解析 ["all"] 哈希。即使其余的哈希解析正常,我也会不断收到此错误。