【发布时间】:2012-07-08 05:05:13
【问题描述】:
在 Rails 中,我如何访问这个 json 的各个元素?我使用 ruby 的 .to_json 方法解析它。json = CSV.parse(csv).to_json。
以下是返回的内容:
[
[
"id",
"subject"
],
[
"1",
"Economics"
],
[
"2",
"General Paper"
],
[
"3",
"History"
],
[
"4",
"Geography"
],
[
"5",
"Mathematics"
],
[
"6",
"Chemistry"
],
[
"7",
"Biology"
],
[
"8",
"Physics"
]
]
尝试访问json[0][1] 或json[0] 返回"["
我感觉它与方括号有关,但我确信有一种方法可以访问它(在我看来,它就像数组中的数组,这种访问方式应该可以工作)
【问题讨论】:
标签: ruby-on-rails arrays ruby-on-rails-3 json