【问题标题】:Rails Parse JSON to hashRails 将 JSON 解析为哈希
【发布时间】:2013-04-14 18:13:34
【问题描述】:

我尝试解析 JSON 响应。

@response = ActiveSupport::JSON.decode(@data.body)

@响应:

{"response"=>[{"name"=>"Den", "other"=>[{"sex"=>"male"}]}]}

如何访问

@response['response']['name'] 

@response['response']['name']['sex']

【问题讨论】:

    标签: ruby-on-rails json parsing


    【解决方案1】:
    @response['response'][0]['name']
    

    @response['response'][0]['other'][0]['sex']
    

    【讨论】:

      猜你喜欢
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 2010-12-26
      • 2014-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多