php 返回json:zabbix:/var/www/html/DEVOPS/Home/Lib/Action# vim EquipmentAction.class.php 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":"ftp\u670d\u52a1\u5668","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 "\n"; } else { die $response->status_line; };print $r;#my $r=encode_utf8($r);my $hash = decode_json($r);print "\n";print $hash->[0]->{info};print "\n";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 "\n"; } else { die $response->status_line; };print $r;my $r=encode_utf8($r);my $hash = decode_json($r);print "\n";print $hash->[0]->{info};print "\n";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服务器