Thread Hilfe bei charset und use utf8 (10 answers)
Opened by bianca at 2014-07-09 19:10

Raubtier
 2014-07-09 20:40
#176356 #176356
User since
2012-05-04
1070 Artikel
BenutzerIn
[default_avatar]
Naja, Zeile 21, in der der Fehler kommt, ist ja die 2. hier:
Code (perl): (dl )
1
2
my $content = $response->decoded_content;
my $ref = JSON->new->utf8->decode($content);


Aus perldoc JSON:
Quote
decode_json
$perl_scalar = decode_json $json_text

The opposite of "encode_json": expects an UTF-8 (binary) string and tries to parse that as an UTF-8 encoded JSON text, returning the
resulting reference.

This function call is functionally identical to:

$perl_scalar = JSON->new->utf8->decode($json_text)


Und aus perldoc HTTP::Response:
Quote
$r->decoded_content( %options )
This will return the content after any "Content-Encoding" and charsets have been decoded. See HTTP::Message for details.


Ersteres will aber einen binary string, du gibst aber einen decodeten String rein. Du darfst JSON also nicht von utf8-binary konvertieren lassen. Sollte also wohl my $ref = JSON->new->utf8(0)->decode($content); heißen.

Edit: siehe auch den Abschnitt "HOW DO I DECODE A DATA FROM OUTER AND ENCODE TO OUTER" im Perldoc. Da ist beschrieben, wie man einen schon decodeten String mit JSON liest.
Last edited: 2014-07-09 20:44:18 +0200 (CEST)

View full thread Hilfe bei charset und use utf8