简体   繁体   English

如何访问此哈希?

[英]How can I access this Hash?

I have this hash: 我有这个哈希:

{
  "EnviarInstrucaoUnicaResponse"=>{
    "xmlns:ns1" => "http://www.moip.com.br/ws/alpha/",
    "Resposta" => {
      "ID"=>"201504171610223590000007515979",
      "Status"=>"Sucesso",
        "Token"=>"Y2F0P1R5G0D4Y1E7A196I1T0O252Z325U9H040M0E0G0Y0V7F581457957X9"
    }
  }
}

How can I acess the "Token" inside it? 如何访问其中的“令牌”?

I've tried <%= @token[EnviarInstrucaoUnicaResponse] %> .... 我已经尝试过<%= @token[EnviarInstrucaoUnicaResponse] %> ...。

Let

Your_Hash = {
  "EnviarInstrucaoUnicaResponse"=>{
    "xmlns:ns1" => "http://www.moip.com.br/ws/alpha/",
    "Resposta" => {
      "ID"=>"201504171610223590000007515979",
      "Status"=>"Sucesso",
        "Token"=>"Y2F0P1R5G0D4Y1E7A196I1T0O252Z325U9H040M0E0G0Y0V7F581457957X9"
    }
  }
}

Then 然后

Token = Your_Hash['EnviarInstrucaoUnicaResponse']['Resposta']['Token']

So what you need to do is: <%= @token[EnviarInstrucaoUnicaResponse]['Resposta']['Token'] %> 因此,您需要做的是: <%= @token[EnviarInstrucaoUnicaResponse]['Resposta']['Token'] %>

Just as you would any hash: 就像任何哈希一样:

@token["EnviarInstrucaoUnicaResponse"]["Reposta"]["Token"]

Your example isn't valid Ruby code. 您的示例不是有效的Ruby代码。 You need to specify keys as strings. 您需要将键指定为字符串。 Other languages will convert automatically for you, like Perl, but not Ruby. 其他语言会自动为您转换,例如Perl,但不会自动转换为Ruby。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM