perl - Auto-encoding Catalyst::View::JSON -


i use dbix class selecting data database; send response controller client using serialization json using catalyst::view::json

but utf8-data selected database needs decoded perl-string utf-8 before sending client this

use encode;  ...  sub get_fruits :path('getfruits') :args(0) {     $fruits = [$c->model('db::fruit')->search({})->hashref_array];     # hated encode data loop     foreach (@$fruits) {         $_->{name} = decode('utf8', $_->{name});     }     $c->stash({fruits => $fruits});     $c->forward('view::json'); } 

is possible decode data automatically in view?

this may simple ensuring catalyst::view::json using json encoder supports utf8 encoding. believe if use json::xs catalyst::view::json perform utf8 encoding default. can make sure catalyst::view::json using json::xs using json_driver config variable.

alternatively can override json encoding in catalyst::view::json detailed in docs


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -