gpt4 book ai didi

ruby-on-rails - rails : get values of http response

转载 作者:可可西里 更新时间:2023-11-01 16:50:12 26 4
gpt4 key购买 nike

在 rails 中,我向一个 api 发帖并得到了响应,但我不知道如何获取信息并找到“代码”变量的值。

$ response 
#<Net::HTTPOK 200 OK readbody=true>

$ puts response.body
{"success":true,"button":{"code":"dfhdsg7f23hjgfs7be7","type":"buy_now","style":"none","text":"Send to MeBrah","name":"MeBrah","description":"Coins you&#x27;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"

关于ruby-on-rails - rails : get values of http response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21542530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com