• Wide character in print at a2.pl line 返回json 需要encode_utf8


    centos6.5:/root/test#cat a2.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 "
    ";
      }
      else 
      {
      die $response->status_line;
      };
    #my $r=encode_utf8($r);
    my $hash = decode_json ( $r );
    print "11111111111111111111
    ";
    print "产品列表
    ";
    print $hash->{data}->{dataList}->[0]->{name};
    print "
    ";
    centos6.5:/root/test#perl a2.pl 
    
    11111111111111111111
    产品列表
    Wide character in print at a2.pl line 40.
    爱晚-融通宝第9期
    
    
    
    因为decode_json必须是unicode字符  ,返回的json数据前需要转成unicode 
    
    my $r=encode_utf8($r);
    
    
    
    
    centos6.5:/root/test#cat a2.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 "
    ";
      }
      else 
      {
      die $response->status_line;
      };
    my $r=encode_utf8($r);
    my $hash = decode_json ( $r );
    print "11111111111111111111
    ";
    print "产品列表
    ";
    print $hash->{data}->{dataList}->[0]->{name};
    print "
    ";
    centos6.5:/root/test#perl a2.pl 
    
    11111111111111111111
    产品列表
    爱晚-融通宝第9期
    

  • 相关阅读:
    基础DP(初级版)
    UVA-816.Abbott's Tevenge (BFS + 打印路径)
    1044: 数圈
    1049: 打牌
    1047: 小A的计算器
    1046: 最小的K个数
    1045: 愚人节的礼物
    1044: 数圈
    1043: 绩点计算
    1042: 小丑排序
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6198988.html
Copyright © 2020-2023  润新知