これは私のjsonファイルです。リスト内のキーtitle
にある値を取得したいと考えています。すなわちLiveHealth
、OneMedical
とvisit guardian
jsonキーに関連付けられた値にアクセスする
{
"data": {
"perksAndWellBeing": [
{
"title": "Physical Wellbeing",
"perks": [
{
"id": "a3N33000EAO",
"logo": "https:933000001P3v1AAC-1.png",
"logoLarge": "https:\33000001P3v6AAC-1.png",
"title": "LiveHealth Online",
},
{
"id": "a3N3300AO",
"logo": "https:\/\-attachments\/06933000001P3uwAAC-1.png",
"logoLarge": "https:/hments\/06933000001P3umAAC-1.png",
"title": "One Medical",
},
{
"id": "a3N3300EA4",
"logo": "https:\/\/s33000001P3vQAAS-1.png",
"logoLarge": "https:\/06933000001P3vVAAS-1.png",
"title": "Access To Top Specialists",
}
]
},
{
"title": "Emotional Wellbeing",
"perks": [
{
"id": null,
"logo": "https:\/\/s00001P3vpAAC-1.png",
"logoLarge": "https:\/\/attachmeOAAS-1.png",
"title": "Visit Guardian EAP",
}
]
},
{
"title": "Financial Wellbeing",
"perks": [
{
"id": "a3N3300HEA4",
"logo": "https:\/\/sg",
"logoLarge": "https:\/SAAS-1.png",
"title": "Track your finances and get free access to financial advice",
},
{
"id": "a3N33000EA4",
"logo": "https:\/\/s",
"logoLarge": "https:\/\/",
"title": "Better student loan refinancing, mortgages, and personal loans",
}
]
},
{
"title": "Perks",
"perks": [
{
"id": "a3N3300LxEAO",
"logo": "https:\/\",
"logoLarge": "https:\/,
"title": "Anthem Programs",
},
{
"id": "a3N3300000EA4",
"logo": "https:\",
"logoLarge": "https:\",
"title": "Receive gym discounts, travel discounts, and more",
}
]
}
]
}
}
現在、私はPhysical wellbeing
とEmotional wellbeing
としての価値を持っているタイトルのを取得することですが、私は、リスト内の値にアクセスすることはできませんよ。
perkswellbeing = JSON.parse(perks)
#puts perkswellbeing
puts "*********************"
g = JSON.parse(perks)
result1 = g["data"]["perksAndWellBeing"].select {|g1| g1['title']}
result1.each do |rest1|
$perks = rest1['title']
puts $perks
私には分かりません!誰も私を助けてくれませんでしたか?
私はあなたのJSONオブジェクトに問題があると思います。 –
@SebastiánPalma私は再確認してください、私に最小限を与える –
私はjson @SebastiánPalmaを更新しました –