ruby - Best way to access the values of a nested hash -


here hash:

{"funds"=>   {"0"=>     {"sector"=>"6555",      "fund_id"=>"4308",      "percent"=>"20.0",      "fund_distribution_id"=>"315304"     }   } } 

how values sector, fund_id etc?

if following undefined method '[]' nil:nilclass because it's looking 'sector' key of '0'

params[:funds].each_with_index |f, index|     puts f[index]['sector'] end 

if

x = {"funds"=>       {"0"=>         {"sector"=>"6555",           "fund_id"=>"4308",           "percent"=>"20.0",           "fund_distribution_id"=>"315304"         }       }     } 

, can value of sector , fund_id by

  x["funds"]["0"]["sector"]   x["funds"]["0"]["fund_id"] 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -