Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created March 21, 2014 02:34
Show Gist options
  • Save memememomo/9678353 to your computer and use it in GitHub Desktop.
Save memememomo/9678353 to your computer and use it in GitHub Desktop.
Mojo::JSONの挙動について ref: http://qiita.com/memememomo/items/39f34587c5eb4222448a
JSON文字列に変換する + utf8フラグを外す
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