Arrays 访问嵌套数组中的特定元素
我正在尝试访问此哈希数组:Arrays 访问嵌套数组中的特定元素,arrays,json,ruby,hash,Arrays,Json,Ruby,Hash,我正在尝试访问此哈希数组: [ { "Book": "1: SS", "Concordance": ". they tugged and heaved at the door, but it wouldn’tbudge, not even when hermione tried her alohomora charm, now what? said ron, these birds … they can’t be here just for decor
[
{
"Book": "1: SS",
"Concordance": ". they tugged and heaved at the door, but it
wouldn’tbudge, not even when hermione tried her alohomora charm, now
what? said ron, these birds … they can’t be here just for decoration,",
"Position": 82471,
"Spell": "alohomora"
},
{
"Book": "1: SS",
"Concordance": "oh, move over, hermione snarled, she grabbed Harry’s
wand, tapped the lock, and whispered, alohomora! the lock clicked and
the door swung open — they piled through it, shut it quickly,",
"Position": 47346,
"Spell": "alohomora"
},
{
"Book": "1: SS",
"Concordance": "it on snape if he showed any sign of wanting to hurt
Harry, now, don’t forget, it’s locomotormortis, hermione muttered as
ron slipped his wand up his sleeve, i know, ron snapped, don’t",
"Position": 65427,
"Spell": "locomotormortis"
},
]
如何访问第二个数组元素中的拼写
?如何访问此阵列的特定字段
我试过做
提及。数据[1][“拼写”]
,但我知道这是错误的。打印提及。数据[1]
,看看Ruby看到了什么
{:Book => "1: SS",
:Concordance =>
"oh, move over, hermione snarled, she grabbed Harry’s \n" +
" wand, tapped the lock, and whispered, alohomora! the lock clicked and \n" +
" the door swung open — they piled through it, shut it quickly,",
:Position => 47346,
:Spell => "alohomora"}
很明显,我们使用:
Mentions.data[1][:Spell] #=> "alohomora"
嗯,这就是你通常访问任何数组的方式。“我知道这是错误的”不是一个足够精确的错误描述,我们无法帮助你。怎么了?怎么会错呢?你怎么知道的?什么不起作用?它怎么不起作用?你的代码有什么问题?你收到错误信息了吗?错误消息是什么?你得到的结果不是你期望的结果吗?你期望得到什么样的结果?为什么?你会得到什么样的结果?两者有什么不同?你观察到的行为是否不是期望的行为?期望的行为是什么?为什么?观察到的行为是什么?它们有什么不同?谢谢!然而,当输入第二个代码建议时,irb返回nil。
提到了什么。数据[1]
返回了什么?