[
"KEY1":{"SUB_KEY1" : "VALUE1","SUB_KEY2" : "VALUE2"},
"KEY2":{"SUB_KEY1" : "VALUE1","SUB_KEY2" : "VALUE2"}
]
The above is my json object which is coming as a response.
如何在Ruby on Rails中获得KEY1
中的SUB_KEY1
和KEY2
中的SUB_KEY1
?
Thank you.
[
"KEY1":{"SUB_KEY1" : "VALUE1","SUB_KEY2" : "VALUE2"},
"KEY2":{"SUB_KEY1" : "VALUE1","SUB_KEY2" : "VALUE2"}
]
The above is my json object which is coming as a response.
如何在Ruby on Rails中获得KEY1
中的SUB_KEY1
和KEY2
中的SUB_KEY1
?
Thank you.
parsed_json = ActiveSupport::JSON.decode(your_json_string)
will parse your string as
[{"KEY1"=>{"SUB_KEY1"=>"VALUE1", "SUB_KEY2"=>"VALUE2"}}, {"KEY2"=>{"SUB_KEY1"=>"VALUE1", "SUB_KEY2"=>"VALUE2"}}]
你应该可以用 parsed_json[1]["KEY2"]["SUB_KEY1"]
个左右的数字来访问它