Skip to content

Instantly share code, notes, and snippets.

@larryzhao
Created March 21, 2012 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larryzhao/2146494 to your computer and use it in GitHub Desktop.
Save larryzhao/2146494 to your computer and use it in GitHub Desktop.
JSON parse test
$ jruby json_text.rb
["に到着を待っている"] is in encoding: UTF-8
に到着を待っている is in encoding ASCII-8BIT
$ ruby json_text.rb
["に到着を待っている"] is in encoding: UTF-8
に到着を待っている is in encoding UTF-8
# encoding: utf-8
require 'json'
Encoding.default_internal = Encoding::UTF_8
json_text = '["に到着を待っている"]'
puts "#{json_text} is in encoding: #{json_text.encoding}"
json_parsed = JSON.parse(json_text)
puts "#{json_parsed.first} is in encoding #{json_parsed.first.encoding}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment