我是 redis 和 ruby 的新手,我正在使用以下代码
response = HTTParty.get('posts.json')
json = JSON(response.body)
json.each do |item|
puts item
puts json[item]
puts item['content']
redis.hset 'latest_posts', item, item['title']
end
puts json[item]
返回以下error no implicit conversion of Hash into Integer
在每个循环中,我想输出键,例如 id、title、content 和 puts item(现在返回整个对象)和 key 中的 json[item] 数据有什么帮助吗?例如,如果我尝试
%w{id title content}.each do |key|
puts key
puts json[key]
end
再次no implicit conversion of String into Integer