【发布时间】:2015-02-10 11:32:01
【问题描述】:
这是我的 JSON 代码
{
"jobs": [
{
"id": 1,
"title": "Software Developer",
"applicants": [
{
"id": 1,
"name": "Rich Hickey",
"tags": ["clojure", "java", "immutability", "datomic", "transducers"]
},
{
"id": 2,
"name": "Guido van Rossum",
"tags": ["python", "google", "bdfl", "drop-box"]
}
]
},
{
"id": 2,
"title": "Software Architect",
"applicants": [
{
"id": 42,
"name": "Rob Pike",
"tags": ["plan-9", "TUPE", "go", "google", "sawzall"]
},
{
"id": 2,
"name": "Guido van Rossum",
"tags": ["python", "google", "bdfl", "drop-box"]
},
{
"id": 1337,
"name": "Jeffrey Dean",
"tags": ["spanner", "BigTable", "MapReduce", "deep learning", "massive clusters"]
}
]
}
]
}
我想使用 ruby 将“工作”列表放入一个数组中。 到目前为止,我有以下代码。
require 'json'
file = File.read(filepath)
data_hash = JSON.parse(file)
如何迭代 data_hash 并选择我想要的信息并将其放入数组中?
【问题讨论】:
-
使用
Hash#each方法迭代。