[root@wx03 ~]# cat a14.pl
use Net::SMTP;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use JSON;
use File::Temp qw/tempfile/;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Data::Dumper;
my $CurrTime = time2iso(time());
my $dis_mainpublish='中均资本';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $now = time();
$ua->agent('Mozilla/5.0');
my $cookie_jar = HTTP::Cookies->new(
file => 'lwp_cookies.txt',
autosave => 1,
ignore_discard => 1
);
$ua->cookie_jar($cookie_jar);
my $response = $ua->get("https://www.zjcap.cn/web/noauth?method=%2Fproduct%2Flist&duration=&entryUnit=&productType=1&status=&yield=&productName=&pageNum=1&pageSize=6&_=1468156037154");
if ($response->is_success) {
$r = $response->decoded_content;
print "\n";
}
else
{
die $response->status_line;
};
#my $r=encode_utf8($r);
my $hash = decode_json ( $r );
print "11111111111111111111\n";
#print Dumper($hash);
print "产品列表\n";
print $hash->{data}->{dataList}->[0]->{name};
[root@wx03 ~]# perl a14.pl
11111111111111111111
产品列表
Wide character in print at a14.pl line 41.
中均-欧洲杯18号(葡萄牙加时/点球夺冠)[root@wx03 ~]#
为什么出现Wide character in print at a14.pl line 41. 呢/
因为my $hash = decode_json ( $r );
$r 没有转换成utf-8 binary string
/****************************************************
[root@wx03 ~]# cat a14.pl
use Net::SMTP;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use JSON;
use File::Temp qw/tempfile/;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Data::Dumper;
my $CurrTime = time2iso(time());
my $dis_mainpublish='中均资本';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $now = time();
$ua->agent('Mozilla/5.0');
my $cookie_jar = HTTP::Cookies->new(
file => 'lwp_cookies.txt',
autosave => 1,
ignore_discard => 1
);
$ua->cookie_jar($cookie_jar);
my $response = $ua->get("https://www.zjcap.cn/web/noauth?method=%2Fproduct%2Flist&duration=&entryUnit=&productType=1&status=&yield=&productName=&pageNum=1&pageSize=6&_=1468156037154");
if ($response->is_success) {
$r = $response->decoded_content;
print "\n";
}
else
{
die $response->status_line;
};
my $r=encode_utf8($r);
my $hash = decode_json ( $r );
print "11111111111111111111\n";
#print Dumper($hash);
print "产品列表\n";
print $hash->{data}->{dataList}->[0]->{name};
[root@wx03 ~]# perl a14.pl
11111111111111111111
产品列表
中均-欧洲杯18号(葡萄牙加时/点球夺冠)[root@wx03 ~]#
转载于:https://www.cnblogs.com/zhaoyangjian724/p/6199635.html