我在使用ruby过滤JSON对象时遇到问题!1.我的JSON对象是由两个哈希组成的大数组。2.哈希包含另一个哈希,其中包含另一个数组和哈希(哦,天哪!:c)。我的目标是输出包含具体价值的Big hash!示例如下:JSON文件就像在
中一样[#That's hash 0{
"id": 0,
"firstName": "",
"lastName": "",
"middleName": null,
"email": "",
"phones": [
null,
null
],
"groups": [{
"id": 0,
"name": ""
}],
"disabled": "",
"technologies": [{
"id": 0,
"name": "",
"children": [{
"id": 1,
"name": "",
"children": [{
"id": 2,
"name": "Farmer",
"children": []
}]
}]
}],
"fullName": ""
},
#That's hash1{
"id": 0,
"firstName": "",
"lastName": "",
"middleName": null,
"email": "",
"phones": [
null,
null
],
"groups": [{
"id": 0,
"name": ""
}],
"disabled": "",
"technologies": [{
"id": 0,
"name": "",
"children": [{
"id": 1,
"name": "",
"children": [{
"id": 2,
"name": "Not Farmer",
"children": []
}]
}]
}],
"fullName": ""
}
]
红宝石上的伪代码(我想要的是:
file = File.read("example.json") #=> Reading JSON file
data_hash = JSON.parse(file, object_class: Hash) #=> Parsing JSON file
data = data_hash.filter #=> filter that hash if "technologies" is not empty!
data.get_hash_by_value(value) #=> For example i put "Not Farmer" in value, and that method must search in all data that (value) and output hash1 for me (because hash0 not include "Not Farmer")
这是个大问题,我不知道该怎么办!!!我的想法是递归查找方法。
我在使用ruby过滤JSON对象时遇到问题! 1.我的JSON对象是由两个散列组成的大数组。 2.哈希包含另一个哈希,其中包含另一个数组和哈希(哦,天哪!:c)。我的...
我编写了自己的函数。也许可以帮助某人。