# JSON Parsing example
require "rubygems"
require "json"
string = '{"desc":{"someKey":"someValue","anotherKey":"value"},"main_item":{"stats":{"a":8,"b":12,"c":10}}}'
parsed = JSON.parse(string) # returns a hash
p parsed["desc"]["someKey"]
p parsed["main_item"]["stats"]["a"]
# Read JSON from a file, iterate over objects
file = open("shops.json")
json = file.read
parsed = JSON.parse(json)
parsed["shop"].each do |shop|
p shop["id"]
end
是预测吗? 谢谢!
答案 0 :(得分:0)
这是Kernel#p
方法。
根据文件:
p(obj) → obj click to toggle source p(obj1, obj2, ...) → [obj, ...] p() → nil
对于每个对象,直接写入obj.inspect后跟换行符 该计划的标准输出。