json icon indicating copy to clipboard operation
json copied to clipboard

decoding of int or string objects

Open zatmonkey opened this issue 12 years ago • 0 comments

I can't decode json encoded strings, numbers, nil and booleans .... the RFC says it's possible : JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays).

alex@Ksso-rMBP:~$ irb
1.9.2p320 :001 > require 'json'
 => true 
1.9.2p320 :002 > JSON.parse("coco".to_json)
JSON::ParserError: 710: unexpected token at '"coco"'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from (irb):2
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'
1.9.2p320 :003 > JSON.parse(12.to_json)
JSON::ParserError: 710: unexpected token at '12'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from (irb):3
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'
1.9.2p320 :004 > JSON.parse(true.to_json)
JSON::ParserError: 710: unexpected token at 'true'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from (irb):4
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'
1.9.2p320 :005 > JSON.parse(nil.to_json)
JSON::ParserError: 710: unexpected token at 'null'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/json/common.rb:146:in `parse'
    from (irb):5
    from /Users/alex/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'

zatmonkey avatar May 31 '13 15:05 zatmonkey