Thread JSON UTF decode (46 answers)
Opened by bianca at 2013-06-17 06:12

GwenDragon
 2013-06-17 22:03
#168388 #168388
User since
2005-01-17
14590 Artikel
Admin1
[Homepage]
user image
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl
require 5.010_001;
use strict;
use warnings;
use lib '.';
use Data::Dumper;
use JSON;
use LWP::UserAgent 6.03;
use CGI ();
use Encode;

my $inhalt;

my $url = 'https://dev.sepatools.eu/supported_banks.json';
my $ua = LWP::UserAgent->new();
#$ua->add_handler("request_send",  sub { shift->dump; return });
#$ua->add_handler("response_done", sub { shift->dump; return });
$ua->ssl_opts('verify_hostname' => 0);
$ua->credentials('dev.sepatools.eu:443',"dev.sepatools.eu",'dtest','8cd9cddec4cdf6780211e4c51d2f287befdff9b7');
my $response = $ua->get($url);
if ($response->is_success) {
        my $content = $response->content;
        my $ref = JSON->new->decode($content);
        
        # Kr€issparkass€ Köln
        my $bank = $ref->{content}[-1]{bankname};
        $bank = Encode::encode('ISO-8859-15',$bank);
        $inhalt =  "Ergebnis:<br><pre>$bank</pre>";
}
else {
        $inhalt = 'Fehler: "'.($response->status_line).'"';
}

my $cgi = CGI->new();
print $cgi->header(
        -content_type => 'text/html', 
        -charset => 'ISO-8859-15'
        ),$inhalt;

Klappt bei mir.

Die SSK Köln hat ein € drin als \u20ac (EURO SIGN' (U+20AC)).
das ist aber nur in ISO-8859-15 (Latin9) oder WINDOWS-1252 vorhanden, nicht in Latin1 (ISO-8859-1)!
Schau mal in http://de.wikipedia.org/wiki/ISO_8859-1#ISO_8859-1... nach. ;)
Last edited: 2013-06-17 22:12:00 +0200 (CEST)
die Drachin Gwen

View full thread JSON UTF decode