perl encode_json 会产生 UTF-8 (binary) string decode_json 需要一个 UTF-8 (binary) string
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 ~]#
perl encode_json 会产生 UTF-8 (binary) string decode_json 需要一个 UTF-8 (binary) string的更多相关文章
- encode_json 会对给定的Perl的数据结构转换为一个UTF-8 encoded, binary string.
use JSON qw/encode_json decode_json/ ; use Encode; my $data = [ { 'name' => 'Ken' , 'age' => 1 ...
- LeetCode 606. Construct String from Binary Tree (建立一个二叉树的string)
You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...
- [No000085]C#反射Demo,通过类名(String)创建类实例,通过方法名(String)调用方法
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...
- 运用String类实现一个模拟用户登录程序
package Test; import java.util.Scanner; // 模拟用户登录程序 // 思路: // 1.用两个String类分别接收用户名和密码 // 2.判断输入的用户名和密 ...
- String数组转List,List转String数组
引入自: http://blog.csdn.net/aaronuu/article/details/7055650 List 转换为 String数组 List<String> list ...
- java基础知识回顾之---java String final类 容易混淆的java String常量池内存分析
/** * 栈(Stack) :存放基本类型的变量数据和对象的引用,但对象本身不存放在栈中,而是存放在堆(new 出来的对象)或者常量池中(字符串常量对象存放 在常量池中). 堆(heap):存 ...
- 17.1.4 Replication and Binary Logging Options and Variables 复制和Binary logging 选项和变量
17.1.4 Replication and Binary Logging Options and Variables 复制和Binary logging 选项和变量 下面的章节包含信息关于mysql ...
- ExtJS学习-----------Ext.String,ExtJS对javascript中的String的扩展
关于ExtJS对javascript中的String的扩展,能够參考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 以 ...
- 一个处理Date与String的工具类
public class DateUtil { private DateUtil(){ } public static final String hhmmFormat="HH:mm" ...
随机推荐
- read/write拥塞与非拥塞
read/write read函数从打开的设备或文件中读取数据. #include <unistd.h> ssize_t read(int fd, void *buf, size_t co ...
- vs2010 调试中监视变量
在msdn中写了如何查看调试的数据,网址: http://msdn.microsoft.com/zh-cn/library/vstudio/esta7c62(v=vs.100).aspx Visual ...
- IT第八天 - 类的应用、debug、项目开发模式优化
IT第八天 上午 类的应用 1.对象在实例化时是非常耗费系统资源的,因此要尽量减少new字段的使用 2.类的初始值是null,在使用未实例化的类时,很容易导致报错:NullExceptionPoint ...
- poj 2833 The Average(堆)
题目链接:http://poj.org/problem?id=2833 思路分析:由于数据量较大,超出存储范围,使用不能使用数组存储数据在进行排序.考虑维护一个最大堆与最小堆,依次读取数据, 记录数据 ...
- Unity Notes调制粒子系统的颗粒的最大数目
Unity该粒子系统是很容易使用.这样的问题是在实际的过程中遇到的:以控制的粒子系统组件的动态需要可产生颗粒的最大数目. 看doc他说,有maxParticles控制.却没有这个开放的參数.仅仅能通过 ...
- 在UITouch事件中画圆圈-iOS8 Swift基础教程
这篇教程主要内容展示如何利用Core Graphics Framework画圆圈,当用户点击屏幕时随机生成不同大小的圆,这篇教程在Xcode6和iOS8下编译通过. 打开Xcode,新建项目选择Sin ...
- ELK 之三:Kibana 使用与Tomcat、Nginx 日志格式处理
一:kibana安装: kibana主要是搜索elasticsearch的数据,并进行数据可视化的展现,新版使用nodejs. 1.下载地址: https://www.elastic.co/downl ...
- ZOJ 3326 An Awful Problem 模拟
只有在 Month 和 Day 都为素数的时候才能得到糖 那就模拟一遍时间即可. //#pragma comment(linker, "/STACK:16777216") //fo ...
- 凡客副总裁被曝离职:或因IPO受阻|凡客|王春焕|离职_互联网_新浪科技_新浪网
凡客副总裁被曝离职:或因IPO受阻|凡客|王春焕|离职_互联网_新浪科技_新浪网 凡客副总裁被曝离职:或因IPO受阻 2013年05月07日 00:56 每日经济新闻 我有话说 每经 ...
- Ubuntu 12.04 (10) Personal Environment - @staticor
Chinese Input ================= I use Wubu, so Fcitx, sudo add-apt-repository ppa:fcitx-team/nightly ...