没有将符号隐式转换为整数:Octokit

no implicit conversion of Symbol into Integer: Octokit

这只是响应正文的一个示例

{
  "users": [
    {
      "login": "octocat",
      "id": 1,
      "node_id": "MDQ6VXNlcjE=",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "gravatar_id": "",
      "url": "https://api.github.com/users/octocat",
      "html_url": "https://github.com/octocat",
      "followers_url": "https://api.github.com/users/octocat/followers",
      "following_url": "https://api.github.com/users/octocat/following{/other_user}",
      "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
      "organizations_url": "https://api.github.com/users/octocat/orgs",
      "repos_url": "https://api.github.com/users/octocat/repos",
      "events_url": "https://api.github.com/users/octocat/events{/privacy}",
      "received_events_url": "https://api.github.com/users/octocat/received_events",
      "type": "User",
      "site_admin": false
    }
  ],
  "teams": [
    {
      "id": 1,
      "node_id": "MDQ6VGVhbTE=",
      "url": "https://api.github.com/teams/1",
      "html_url": "https://github.com/orgs/github/teams/justice-league",
      "name": "Justice League",
      "slug": "justice-league",
      "description": "A great team.",
      "privacy": "closed",
      "permission": "admin",
      "members_url": "https://api.github.com/teams/1/members{/member}",
      "repositories_url": "https://api.github.com/teams/1/repos",
      "parent": null
    }
  ]
}
 client.pull_request_reviewer("healtheintent/hcc_reference_service", 129).each do |comment|
    username = comment[:user][:login]
end

这是我用来迭代给定响应的代码。 但它返回“没有将符号隐式转换为整数”

谁能告诉我如何迭代给定的正文

您访问内容的“路径”(comment[:user][:login]) 与您的数据结构完全不匹配。

  1. users 不是 user
  2. 根对象是散列,不是数组
  3. 您有一个嵌套数组,您没有对其进行迭代

也许你想要这个

client.pull_request_reviewer("healtheintent/hcc_reference_service", 129)[:users].each do |user|
    username = user[:login]

你得到“没有将符号隐式转换为整数”的原因是,因为你在数组上使用 [] 符号,但给它一个符号 key/index (因为你错误地认为是哈希)