Consider this :)(error message, ignore the choice of bytes)
$ perl -MEncode -MJSON -e " print JSON->new->utf8(0)->pretty(1)->encod +e([ decode 'utf8', qq{\xFA\xFG} ]); " Wide character in print at -e line 1. [ "�\u000fG" ] $ perl -MEncode -MJSON -e " print JSON->new->ascii(1)->pretty(1)->enco +de([ decode 'utf8', qq{\xFA\xFG} ]); " [ "\ufffd\u000fG" ]
The error Body must be bytes and should not contain wide characters (UTF-8 strings) comes from Plack::Middleware::Lint, and I remember a similar message from LWP/HTTP::Message. I've learned from perlunitut: Unicode in Perl#I/O flow (the actual 5 minute tutorial) that this means you have to write
return encode 'UTF-8', JSON->...
I write JSON because JSON loads JSON::XS if its available, but the code doesn't break of JSON::XS isn't available for some reason :)
This is confirmed by PSGI::FAQ#I want to send Unicode content in the HTTP response. How can I do so?
I'm wouldn't be surprised if there exists a Plack::Middleware::Encoding or some such which automatically encodes your UTF-8 strings and adds a charset header, but I haven't seen one
In reply to Re: utf8/yui/json/ajax/plack troubles
by Anonymous Monk
in thread utf8/yui/json/ajax/plack troubles
by ron.savage
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |