简体   繁体   中英

Ruby - Iterate over parsed json with no hash name

So I'm trying to do some work with JIRA's REST API to get our upcoming releases schedule. From their API I can get returned JSON as seen below:

[{
"self": "https://jira.company.com/rest/api/2/version/15701",
"id": "15701",
"description": "First release",
"name": "1.4.3",
"archived": false,
"released": true,
"releaseDate": "2013-02-28",
"userReleaseDate": "28/Feb/13",
"projectId": 10005
},
{
"self": "https://jira.company.com/rest/api/2/version/15685",
"id": "15685",
"description": "Second release",
"name": "1.4.5",
"archived": false,
"released": true,
"releaseDate": "2013-03-11",
"userReleaseDate": "11/Mar/13",
"projectId": 10005
}
]

So I've looked over other answers on the site and I can't quite figure out when I have a block that doesn't have an identifier. For example this question, reddit's api names each json object while JIRA does not. Ruby - iterate over parsed JSON

I've tried something along the lines of

json[''].each do |release|
    puts release['description']
end

But that's where I'm a bit lost. I put [''] because there is no key to go off there. I'm quite new to JSON so my terminology might be way off here too...

You will be given an Array object when you parse that JSON string.

If you write the following code:

json.each do |release|
  puts release['self']
end

You should see this output:

https://jira.company.com/rest/api/2/version/15685
https://jira.company.com/rest/api/2/version/15701

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM