Created
December 20, 2013 04:26
-
-
Save gabu/8050406 to your computer and use it in GitHub Desktop.
RubyでJSONのencode/decodeの比較をしてみた結果、ArrayもHashも元に戻る。
さすがにHashのKeyのシンボルはシンボルには戻らなかった。そりゃそうだ感あるけど。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ irb [~] | |
irb(main):001:0> require 'json' | |
=> true | |
irb(main):002:0> 1.to_json | |
=> "1" | |
irb(main):003:0> JSON.load(1.to_json) | |
=> 1 | |
irb(main):004:0> 1 === JSON.load(1.to_json) | |
=> true | |
irb(main):005:0> "hoge" === JSON.load("hoge".to_json) | |
=> true | |
irb(main):006:0> [1, 2, 3] === JSON.load([1, 2, 3].to_json) | |
=> true | |
irb(main):007:0> {:a => 1, :b => 2} === JSON.load({:a => 1, :b => 2}.to_json) | |
=> false | |
irb(main):008:0> JSON.load({:a => 1, :b => 2}.to_json) | |
=> {"a"=>1, "b"=>2} | |
irb(main):009:0> {"a" => 1, "b" => 2} === JSON.load({"a" => 1, "b" => 2}.to_json) | |
=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment