Igor Martins
Igor Martins

Reputation: 2047

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] %> ....

Upvotes: 0

Views: 51

Answers (2)

tadman
tadman

Reputation: 211740

Just as you would any hash:

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

Your example isn't valid Ruby code. You need to specify keys as strings. Other languages will convert automatically for you, like Perl, but not Ruby.

Upvotes: 1

Alfie
Alfie

Reputation: 2784

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'] %>

Upvotes: 1

Related Questions