Created
June 3, 2015 14:03
-
-
Save tamtam180/29028c011abdd36ae0ef to your computer and use it in GitHub Desktop.
Revisions
-
tamtam180 created this gist
Jun 3, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ # coding: utf-8 require 'json' require 'yajl' x = eval('{"logType"=>"ads", "abc"=>"\xE3\x82\xA4\xE3\x83\xB3\xE3\x82\xB9\xE3\x83\x88\xE3\x83\xBC\xE3\x83\xAB", "time"=>"2015-05-17T03:00:00Z", "tag"=>"aaa"}') puts x["abc"].force_encoding("ASCII-8BIT") puts x["abc"].encoding puts x puts Yajl.dump(x) puts JSON.dump(x) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ インストール ASCII-8BIT {"logType"=>"ads", "abc"=>"\xE3\x82\xA4\xE3\x83\xB3\xE3\x82\xB9\xE3\x83\x88\xE3\x83\xBC\xE3\x83\xAB", "time"=>"2015-05-17T03:00:00Z", "tag"=>"aaa"} {"logType":"ads","abc":"インストール","time":"2015-05-17T03:00:00Z","tag":"aaa"} /Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:223:in `encode': "\xE3" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) from /Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:223:in `generate' from /Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:223:in `generate' from /Library/Ruby/Gems/2.0.0/gems/json-1.8.1/lib/json/common.rb:394:in `dump' from hoge.rb:12:in `<main>'