zoukankan      html  css  js  c++  java
  • 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服务器
    


    
                                        
    
  • 相关阅读:
    Response.Status http协议状态代码
    ASP.NET MVC 如何实现头压缩
    Google PR值原理和详细解说
    NodeJS 深入浅出
    C#: ToString格式
    HttpHandler实现媒体文件和图像文件的盗链(防盗链设计)
    ASP.NET MVC 使用Areas功能的常见错误
    VC中利用多线程技术实现线程之间的通信
    基于Visual C++的Winsock API研究
    键盘钩子程序
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350033.html
Copyright © 2011-2022 走看看