散列内的值

时间:2014-09-30 12:32:10

标签: ruby hashmap

我对哈希有一些问题:

"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
     }

如何获得' commissionValue'?

的价值

1 个答案:

答案 0 :(得分:2)

使用[]按键获取哈希值。

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