• php 返回json 解析 报Wide character in print


    php 返回json:
    zabbix:/var/www/html/DEVOPS/Home/Lib/Action# vim EquipmentAction.class.php 
    
    <?php
    header('Content-Type:application/json; charset=utf-8');  ##返回json php文件格式为utf-8 无BOM格式
    
    
           public function search_ipadd(){
                    $where['ip'] = $_GET['ip'];
                    $Machine = M('Machine_info');
                    $arr = $Machine->where($where)->select();
                    echo json_encode($arr);
             }
    
    
    
    
            public function search_ipadd(){
                    $where['ip'] = $_GET['ip'];
                    $Machine = M('Machine_info');
                    $arr = $Machine->where($where)->select();
                    $str= json_encode($arr);
                     echo preg_replace("#\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\1'))", $str);
    
             }
    
    
    
    
        echo preg_replace("#\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\1'))", $str);
    
        解决返回[{"sn":"83","ip":"192.168.11.187","info":"ftpu670du52a1u5668","env":"esx-192.168.4.44"}] 
       
    
    
    /*****************************************************************************
    
    
    centos6.5:/root#cat a1.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("http://192.168.11.186/DEVOPS/index.php/Equipment/search_ipadd?ip=192.168.11.187");
    
    
    if ($response->is_success) {
      $r = $response->decoded_content; 
      print "
    "; }
      else
      {
      die $response->status_line; };
    print $r;
    #my $r=encode_utf8($r);
    my $hash = decode_json($r);
    print "
    ";
    print $hash->[0]->{info};
    print "
    ";
    centos6.5:/root#perl a1.pl 
    
    [{"sn":"83","ip":"192.168.11.187","info":"ftp服务器","env":"esx-192.168.4.44"}]
    Wide character in print at a1.pl line 38.
    ftp服务器
    
    
    解决 Wide character in print at a1.pl line 38.
    
    
    centos6.5:/root#vim a1.pl 
    centos6.5:/root#cat a1.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("http://192.168.11.186/DEVOPS/index.php/Equipment/search_ipadd?ip=192.168.11.187");
    
    
    if ($response->is_success) {
      $r = $response->decoded_content; 
      print "
    "; }
      else
      {
      die $response->status_line; };
    print $r;
    my $r=encode_utf8($r);
    my $hash = decode_json($r);
    print "
    ";
    print $hash->[0]->{info};
    print "
    ";
    centos6.5:/root#
    centos6.5:/root#perl a1.pl 
    
    [{"sn":"83","ip":"192.168.11.187","info":"ftp服务器","env":"esx-192.168.4.44"}]
    ftp服务器
    


    
       
    
  • 相关阅读:
    gitlab安装配置
    jenkins忘记admin密码的处理方法
    jenkins权限管理插件role-based(二)
    jenkins安装部署(一)
    ERROR 1129 (HY000): Host '192.168.7.210' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
    nginx重试机制proxy_next_upstream
    nginx配置ssi
    python实现查找指定文件
    python 调用系统命令
    Android 调用资源字符串的几种方法
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6198987.html
Copyright © 2020-2023  润新知