我正在尝试在 Ruby 中解析输出的一些 JSON 值,但我不断得到意外的结果。
articlelist = client.get('/v1/my_data/articles')
#debug
puts (articlelist.body)
#Parse the article list and get values
parsed = JSON.parse(articlelist.body)
puts parsed.count
parsed.count do
|currentfile|
inputfile = File.open ('file.example')#file.example should be replaced with local file
filehash = OpenSSL::Digest.new('sha256', 'inputfile')
puts "#{inputfile} has #{filehash.name} hash of #{filehash}"#debug
end
我得到以下结果:
{"count": 0, "items": []}
2
#<File:0x00000001a83b48> has SHA256 hash of 3de6c8f12dc4c9efe67c0a5bbfe21502cde5ee22e7ef0bc8d348c696db9a4363
#<File:0x00000001a83238> has SHA256 hash of 3de6c8f12dc4c9efe67c0a5bbfe21502cde5ee22e7ef0bc8d348c696db9a4363
如果 的值count
为零,为什么它给我的计数值为 2(输入文件只是本地示例文件)?