首页 技术 正文
技术 2022年11月18日
0 收藏 417 点赞 4,566 浏览 2093 个字
encode_json    $json_text = encode_json $perl_scalar
Converts the given Perl data structure to a UTF-8 encoded, binary string.This function call is functionally identical to: $json_text = JSON->new->utf8->encode($perl_scalar) 转换给定的perl数据结构到一个UTF-8编码的,2进制的字符串。 encode_json 产生一个UTF-8编码的2进制字符[root@wx03 ~]# cat a15.pl
use JSON qw/encode_json decode_json/ ;
use Encode;
my $data = [
{
'name' => 'Ken' ,
'age' => 19
},
{
'name' => '测试' ,
'age' => 25
}
];
my $json_out = encode_json ( $data );
print $json_out;
print "\n";my $d=decode_utf8($json_out);
print $d;
print "\n";[root@wx03 ~]# perl a15.pl
[{"age":19,"name":"Ken"},{"age":25,"name":"测试"}]
[{"age":19,"name":"Ken"},{"age":25,"name":"测试"}]encode_json 会产生一个utf-8的2进制格式 decode_json $perl_scalar = decode_json $json_text
The opposite of encode_json: expects an UTF-8 (binary) string and tries to parse that as an UTF-8 encoded JSON text, returning the resulting reference.This function call is functionally identical to: $perl_scalar = JSON->new->utf8->decode($json_text) 与encode-接送相反,期望一个UTF-8(2进制)字符串尝试解析一个 UTF-8编码的JSON 文本, 返回一个结果引用。 decode_json 必须是unicode形式的字符,是一个UTF-8的2进制字符串 [root@wx03 ~]# cat a14.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 "\n";
}
else
{
die $response->status_line;
};my $r=encode_utf8($r);
my $hash = decode_json ( $r );
print "11111111111111111111\n";
#print Dumper($hash);
print "产品列表\n";
print $hash->{data}->{dataList}->[0]->{name};
[root@wx03 ~]# perl a14.pl 11111111111111111111
产品列表
中均-欧洲杯18号(葡萄牙加时/点球夺冠)[root@wx03 ~]#
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893