0
請求一些API後,我得到一個json哈希。我想要的是通過該哈希循環來獲取標籤,但我得到no implicit conversion of String into Integer
。請提供任何幫助或更好的方法?Rails解析json
{
"status": "OK",
"result": [
{
"verdict": "OK",
"problem": {
"tags": [
"implementation", ...
]
}
},
.
.
]
}
型號/ codeforces_api.rb
def self.retrieve_results(current_user)
json = JSON.parse(open("http://codeforces.com/api/user.status?handle=#{current_user.code_forces_handle}&key='my-key'&secret='my-secret'").read).to_json
ActiveSupport::JSON.decode(json)["result"].each do |record|
if record["verdict"] == "OK"
record ["problem"].each do |problem|
problem ["tags"].each do |tag|
puts tag
end
end
end
end
end
它的工作原理,謝謝。 –