Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Parse JSON to hash

I try parse JSON response.

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

@response:

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

how to access

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

and

@response['response']['name']['sex']
like image 883
user2232650 Avatar asked Apr 11 '26 00:04

user2232650


1 Answers

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

and

@response['response'][0]['other'][0]['sex']
like image 159
ted Avatar answered Apr 13 '26 15:04

ted