Rails:获取http响应的值

在rails中我发了一个api的post并得到了回复,但我不知道如何获取信息并找到“code”变量的值。

$ response # $ puts response.body {"success":true,"button":{"code":"dfhdsg7f23hjgfs7be7","type":"buy_now","style":"none","text":"Send to MeBrah","name":"MeBrah","description":"Coins you're willing to give me.","custom":"6","callback_url":null,"success_url":null,"cancel_url":null,"info_url":null,"auto_redirect":false,"price":{"cents":40000000,"currency_iso":"BTC"},"variable_price":true,"choose_price":false,"include_address":false,"include_email":false}} $ response.code "200" 

我知道代码变量也是相同的“dfhdsg7f23hjgfs7be7”我只是好奇什么命令会返回它的值。

使用JSON.parse解析响应内容:

 require 'json' ... data = JSON.parse(response.body) data['button']['code'] # => "dfhdsg7f23hjgfs7be7"