-4

I have some problems with a hash:

"commissions"=>
  {"commission"=>
    {"commissionID"=>"38767647",
     "date"=>"2014-09-22",
     "publisherID"=>"46272",
     "domainID"=>"1173659",
     "merchantID"=>"35216",
     "commissionValue"=>110,
     "orderValue"=>2095,
     "currency"=>"USD",
     "url"=>"http://www.asos.com"},
   "commission5"=>
    {
     other params
     }

How can I get the value of 'commissionValue'?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
sts
  • 380
  • 3
  • 11
  • possible duplicate of [Ruby access hash element](http://stackoverflow.com/questions/4910621/ruby-access-hash-element) – Roman Kiselenko Sep 30 '14 at 12:37
  • possible duplicate of [Access Ruby hash variables](http://stackoverflow.com/questions/16194219/access-ruby-hash-variables) – Santhosh Sep 30 '14 at 13:30
  • possible duplicate of [Accessing elements of nested hashes in ruby](http://stackoverflow.com/questions/5544858/accessing-elements-of-nested-hashes-in-ruby) – Holger Just Sep 30 '14 at 14:04
  • When you supply data, such as what should be a hash definition, it's really important to make sure it's a valid definition, otherwise we have to figure out first whether that's the problem. Please take the time to format it for readability also, as that helps us help you. – the Tin Man Sep 30 '14 at 16:08

1 Answers1

2

Use [] to get value of the hash by key.

h = {"commissions"=>
  {"commission"=>
    {"commissionID"=>"38767647",
      "date"=>"2014-09-22",
      "publisherID"=>"46272",
      "domainID"=>"1173659",
      "merchantID"=>"35216",
      "commissionValue"=>110,
      "orderValue"=>2095,
      "currency"=>"USD",
      "url"=>"http://www.asos.com"},
      "commission5"=> { }
  }
}
h["commissions"]["commission"]["commissionValue"]
# => 110
falsetru
  • 357,413
  • 63
  • 732
  • 636