我正在尝试从这个嵌套的JSON数据中解析出我需要的值。我需要从quotas获取是responders,我需要从qualified获取是service_id,codes。
我首先尝试只获取quotas,但一直收到以下错误[]': no implicit conversion of String into Integer
hash = JSON::parse(response.body)
hash.each do |data|
p data["quotas"]
endJson数据
{
"id": 14706,
"relationships" : [
{
"id": 538
}
]
"quotas": [
{
"id": 48894,
"name": "Test",
"responders": 6,
"qualified": [
{
"service_id": 12,
"codes": [
1,
2,
3,
6,
]
},
{
"service_id": 23,
"pre_codes": [
1,
2
]
}
]
}
]
}发布于 2021-07-25 06:33:32
我需要把你的例子转换成json。然后我可以循环配额并输出值。
hash = JSON::parse(data.to_json)
hash['quotas'].each do |data|
p data["responders"]
data["qualified"].each do |responder|
p responder['service_id']
p responder['codes']
end
endHash in data变量(示例代码工作所必需的):
require "json"
data = {
"id": 14706,
"relationships": [
{
"id": 538
}
],
"quotas": [
{
"id": 48894,
"name": "Test",
"responders": 6,
"qualified": [
{
"service_id": 12,
"codes": [
1,
2,
3,
6,
]
},
{
"service_id": 23,
"pre_codes": [
1,
2
]
}
]
}
]
} https://stackoverflow.com/questions/68514162
复制相似问题