【发布时间】:2011-06-22 10:34:39
【问题描述】:
ruby-1.9.2-p0 > require 'json'
=> true
ruby-1.9.2-p0 > hash = {hi: "sup", yo: "hey"}
=> {:hi=>"sup", :yo=>"hey"}
ruby-1.9.2-p0 > hash.to_json
=> "{\"hi\":\"sup\",\"yo\":\"hey\"}"
ruby-1.9.2-p0 > j hash
{"hi":"sup","yo":"hey"}
=> nil
j hash 输入我想要的答案,但返回nil。
hash.to_json 用反斜杠返回我想要的答案。我不想要反斜杠。
【问题讨论】:
-
我用 STDOUT 和返回值更新了问题。
-
太好了,我不存在。我们经常使用 y 来格式化哈希和对象。