无法将 String 转换为整数或 [] 的未定义方法 nil
使用 Httparty,当我使用以下代码访问 @no
时,我得到以下响应
@parsed_reponse = > {"items" => {"@no" => "1", "@type" => "book", "@category" => "GENERAL" }}
,我得到 以下错误:“无法将字符串转换为整数”
r = @response.parsed_response["items"]["@no"]
有人可以帮忙吗?我确实得到“无法将字符串转换为整数” 或“nil:NilClass (NoMethodError) 的未定义方法‘[]’”
任何人都可以用示例解释这一点吗?
Using Httparty, I get the following response
@parsed_reponse = > {"items" => {"@no" => "1", "@type" => "book", "@category" => "GENERAL" }}
when i use the following code to access @no
, I am getting the
following error: "Can't convert String into Integer"
r = @response.parsed_response["items"]["@no"]
Can anyone help on this? I do get "Can't convert String into Integer"
or "Undefined method `[]' for nil:NilClass (NoMethodError)"
Can anyone explain this with an example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 HTTParty 专家,但以下是我迭代响应中所有数据的示例:
I am no HTTParty expert but here is an example of what I do to iterate through all the data in a response: