Rails将JSON解析为哈希

时间:2013-04-14 18:13:34

标签: ruby-on-rails json parsing

我尝试解析JSON响应。

@response = ActiveSupport::JSON.decode(@data.body)

@应答:

{"response"=>[{"name"=>"Den", "other"=>[{"sex"=>"male"}]}]}

如何访问

@response['response']['name'] 

@response['response']['name']['sex']

1 个答案:

答案 0 :(得分:8)

@response['response'][0]['name']

@response['response'][0]['other'][0]['sex']