新手问题 get 一个 url 会返回一个 json 数据,怎么在 rails 里得到这个返回的 json?

7LI · 2012年08月20日 · 最后由 7LI 回复于 2012年08月20日 · 4672 次阅读

https://graph.renren.com/oauth/token?grant_type=authorization_code&client_id=xxx&redirect_uri=xxx&client_secret=xxx&code=xxx 是这样的一个 url,当 get 这个 url 时候,他会返回一个 json 数据,那我如何在 controller 里得到这个 json?

response.body

看看 open-uri 的文档,在 Ruby 官方文档里面

简单来说

require 'open-uri'

JSON.parse(open('http://....').read)
需要 登录 后方可回复, 如果你还没有账号请 注册新账号