0
我是新来的Redis和红宝石我使用下面的代码导入JSON数据为Redis的
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键,标题,内容与放置项目(现在返回整个对象)和JSON的[项目]数据的任何帮助?如果我尝试例如
%w{id title content}.each do |key|
puts key
puts json[key]
end
再次no implicit conversion of String into Integer
什么是'json'分配给?你确定你使用的是正确的吗?通常你会看到'JSON.load(response.body)'。 – tadman
我使用HTTParty来加载json是一个变量分配给json对象只是一个名字 – sger
你应该'把json.inspect'放在第三行以确保它是正确的类型。当你调用字符串或数组上的'[]'时,你得到的错误往往会发生什么。同样'把json [item] .inspect'放在循环中。 – tadman