0

LinkedInからハッシュを解析しようとしていますが、エラーが発生します

これが私が解析しようとしているハッシュ(マッシュから変換された)です:

#<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"]ハッシュを解析しているようです。残りのハッシュは正常に解析されますが、このエラーが発生し続けます。

4

1 に答える 1

0

connection["positions"]あなたの例では配列を返しません。単一のLinkedIn::Mashハッシュ オブジェクトを返します。あなたは間違ってそれを呼ん.eachでいます。

于 2012-12-27T22:38:57.440 に答える