Mike Tonks wrote:

Hope it's ok to mail you directly.

Yeah, that's fine, but I'm cc'ing the C::A list so that others can benefit from this discussion. Also, sorry for taking so long to get back to you on this.

I recently added your
CGI::Application::Plugin::JSON module to my project, and was very
pleased until I noticed my french language stuff with utf8 characters,
accents and so on, was mangled in the output.

I have temporarily abandonned the plugin and replaced the code as follows:

# send the JSON in the document body (removed)
#$self->json_body( $data );

# Signal to JSON::Any to use utf8
$ENV{JSON_ANY_CONFIG}     = "utf8=1";

my $j = JSON::Any->new;
my $json = $j->encode($data);

return $json;

Since CAP::JSON uses JSON::Any and it calls encode() then you should just be able to set $ENV{JSON_ANY_CONFIG} = "utf8=1" in your application somewhere (probably in the prerun or init stages).

Just wondered if you had come across this and had any thoughts or suggestions.

But since the JSON_ANY_CONFIG thing isn't documented anywhere, it's probably best to use something else. How about $self->json_args()? It would just keep the args around and pass them to JSON::Any's new() method. So in your init/prerun you'd do something like this:

  $self->json_args(utf8 => 1);

And now that I think about it, all these json_* methods are kind of annoying. I probably should have gone with $self->json->* instead. Oh well...

--
Michael Peters
Plus Three, LP


#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################

Reply via email to