zoukankan      html  css  js  c++  java
  • perl $d = encode_utf8($r); $f = decode_json($d)

    [root@dr-mysql01 ~]# cat a1.pl
    my $url="http://192.168.32.101:3000/api/getcode?env=zj&phone=180727xx237";
    use  LWP::UserAgent;
    use Encode;
     
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    $ua->agent("Mozilla/8.0");
    
    my $response = $ua->get($url);
    
    
    
    if ($response->is_success) {
     $r= $response->decoded_content;  # or whatever
    }
    else {
     die $response->status_line;
    };
     use JSON qw/encode_json decode_json/;
     $d       = encode_utf8($r);
     $f       = decode_json($d);
    print $f;
    print "
    ";
    use Data::Dumper;
    my $var= Dumper($f);
    print $var;
    print "
    ";
    print $f->[0]->[1];
    [root@dr-mysql01 ~]# perl a1.pl
    ARRAY(0x1315750)
    $VAR1 = [
              [
                '18072722237',
                "ZJx{e6}x{b2}x{a1}x{e6}x{9c}x{89}x{e6}x{89}x{be}x{e5}x{88}x{b0}x{e9}x{9c}x{80}x{e8}x{a6}x{81}x{e7}x{9a}x{84}x{e9}x{aa}x{8c}x{e8}x{af}x{81}x{e7}x{a0}x{81}x{e4}x{bf}x{a1}x{e6}x{81}x{af}"
              ]
            ];
    
    ZJ没有找到需要的验证码信息[root@dr-mysql01 ~]# 
    
    
    
    [root@dr-mysql01 ~]# cat a2.pl 
    my $url="http://192.168.32.101:3000/api/getcode?env=zj&phone=180727xx237";
    use  LWP::UserAgent;
    use Encode;
     
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    $ua->agent("Mozilla/8.0");
    
    my $response = $ua->get($url);
    
    
    
    if ($response->is_success) {
     $r= $response->decoded_content;  # or whatever
    }
    else {
     die $response->status_line;
    };
     use JSON qw/encode_json decode_json/;
     #$d       = encode_utf8($r);
     $f       = decode_json($r);
    print $f;
    print "
    ";
    use Data::Dumper;
    my $var= Dumper($f);
    print $var;
    print "
    ";
    print $f->[0]->[1];
    [root@dr-mysql01 ~]# perl a2.pl 
    ARRAY(0x1f3e878)
    $VAR1 = [
              [
                '18072722237',
                "ZJx{6ca1}x{6709}x{627e}x{5230}x{9700}x{8981}x{7684}x{9a8c}x{8bc1}x{7801}x{4fe1}x{606f}"
              ]
            ];
    
    Wide character in print at a2.pl line 29.
    ZJ没有找到需要的验证码信息[root@dr-mysql01 ~]# 
    
    在数据中含有UTF-8字符的时候需要稍微注意,如果直接按照上面的方法将会出现乱码。JSON模块的encode_json和decode_json自身是支持UTF8编码的,但是perl为了简洁高效,默认是认为程序是非UTF8的,因此在程序开头处需要申明需要UTF8支持
    

  • 相关阅读:
    C#各自定义控件的网址链接
    给应用程序加装“看门狗”
    CRT detected that the application wrote to memory after after the end of heap buffer(这个经常忘掉)
    关于C#中的Delegate的一些知识
    实行项目管理信息化的好处
    C#连接池的详细分析(转)
    .Net Remoting和Web Service大比拼(转)
    使用SqlDataSource调用带参数存储过程插入数据
    156转换为byte时为什么会变成100的解释
    站在“组织者”这个角色上
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6200014.html
Copyright © 2011-2022 走看看