【发布时间】:2017-11-21 12:18:32
【问题描述】:
我正在通过 HTTParty 从外部 API 获取令牌。
我的电话是这样的:
token_request = HTTParty.post(@url, body: token_payload.to_json, headers: { 'Content-Type' => 'application/json' })
我收到以下 JSON:
{"token":"TBpdV20Fsdbycgmib2B8ZhasVnRb","expiration_utctimestamp":"23123202226","error_code":0,"error_message":null}
我现在想将令牌值传递给我的下一个请求。
如何将“TBpdV20Fsdbycgmib2B8ZhasVnRb”位放入变量中?我的猜测是这样,但不起作用:
token = token_request[:token]
谢谢
【问题讨论】:
-
token_request['token']怎么样?正如您在输出中看到的,键是字符串,而不是符号。 -
如果我将 :token 更改为 'token' 它只会在终端中返回字符串:'token'。不过,我想要的是价值,而不是钥匙。
-
好的,那么
token_request变量究竟包含什么? -
Exact output in terminal@MarekLipka
标签: ruby-on-rails json parsing httparty