Created
March 21, 2014 02:34
-
-
Save memememomo/9678353 to your computer and use it in GitHub Desktop.
Mojo::JSONの挙動について ref: http://qiita.com/memememomo/items/39f34587c5eb4222448a
This file contains 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
JSON文字列に変換する + utf8フラグを外す |
This file contains 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
use Mojolicious::Lite; | |
use utf8; | |
use Encode; | |
get '/' => sub { | |
my $self = shift; | |
my %data = ('name' => '太郎'); | |
# $json には、utf8フラグが付いていないJSON文字列が入る | |
my $json = $self->render(partial => 1, json => \%data); | |
# renderで描画する場合は、Encode::decodeを使う | |
$self->render(json => decode_utf8($json)); | |
} => 'index'; | |
app->start; | |
__DATA__ | |
@@ index.html.ep | |
<% my ($json) = @_; %> | |
<%= $json %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment