我有这个哈希:
{
"EnviarInstrucaoUnicaResponse"=>{
"xmlns:ns1" => "http://www.moip.com.br/ws/alpha/",
"Resposta" => {
"ID"=>"201504171610223590000007515979",
"Status"=>"Sucesso",
"Token"=>"Y2F0P1R5G0D4Y1E7A196I1T0O252Z325U9H040M0E0G0Y0V7F581457957X9"
}
}
}
如何访问其中的“令牌”?
我试过<%= @token[EnviarInstrucaoUnicaResponse] %>
....
答案 0 :(得分:1)
让
Your_Hash = {
"EnviarInstrucaoUnicaResponse"=>{
"xmlns:ns1" => "http://www.moip.com.br/ws/alpha/",
"Resposta" => {
"ID"=>"201504171610223590000007515979",
"Status"=>"Sucesso",
"Token"=>"Y2F0P1R5G0D4Y1E7A196I1T0O252Z325U9H040M0E0G0Y0V7F581457957X9"
}
}
}
然后
Token = Your_Hash['EnviarInstrucaoUnicaResponse']['Resposta']['Token']
所以你需要做的是:<%= @token[EnviarInstrucaoUnicaResponse]['Resposta']['Token'] %>
答案 1 :(得分:1)
就像你对任何哈希一样:
@token["EnviarInstrucaoUnicaResponse"]["Reposta"]["Token"]
您的示例不是有效的Ruby代码。您需要将键指定为字符串。其他语言将自动为您转换,如Perl,但不是Ruby。