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的更多相关文章

  1. encode_json 会对给定的Perl的数据结构转换为一个UTF-8 encoded, binary string.

    use JSON qw/encode_json decode_json/ ; use Encode; my $data = [ { 'name' => 'Ken' , 'age' => 1 ...

  2. 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 ...

  3. [No000085]C#反射Demo,通过类名(String)创建类实例,通过方法名(String)调用方法

    using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...

  4. 运用String类实现一个模拟用户登录程序

    package Test; import java.util.Scanner; // 模拟用户登录程序 // 思路: // 1.用两个String类分别接收用户名和密码 // 2.判断输入的用户名和密 ...

  5. String数组转List,List转String数组

    引入自: http://blog.csdn.net/aaronuu/article/details/7055650 List 转换为 String数组 List<String> list  ...

  6. java基础知识回顾之---java String final类 容易混淆的java String常量池内存分析

    /** *   栈(Stack) :存放基本类型的变量数据和对象的引用,但对象本身不存放在栈中,而是存放在堆(new 出来的对象)或者常量池中(字符串常量对象存放  在常量池中). 堆(heap):存 ...

  7. 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 ...

  8. ExtJS学习-----------Ext.String,ExtJS对javascript中的String的扩展

    关于ExtJS对javascript中的String的扩展,能够參考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 以 ...

  9. 一个处理Date与String的工具类

    public class DateUtil { private DateUtil(){ } public static final String hhmmFormat="HH:mm" ...

随机推荐

  1. 分支-15. 日K蜡烛图(15)

    #include<iostream> using namespace std; int main(){ float o,h,l,c; while(cin>>o>>h ...

  2. 数组排序-Objectivec

    发表于昨天(23:33)(2013-11-03 23:33) ,已有15次阅读 ,共0个评论 摘要: 总结OC中数组排序3种方法:sortedArrayUsingSelector:;sortedArr ...

  3. Week15(12月19日):授课综述2

    Part I:提问 =========================== 1.为了编辑应用程序的统一布局,可打开位于Views\Shared子目录中的(    )文件. A.MasterPage.h ...

  4. QR码生成原理

    一.什么是QR码 QR码属于矩阵式二维码中的一个种类,由DENSO(日本电装)公司开发,由JIS和ISO将其标准化.QR码的样子其实在很多场合已经能够被看到了,我这还是贴个图展示一下: 这个图如果被正 ...

  5. Qt见解:Post 与 Get 的区别(Get将参数直接与网址整合为一个整体,而Post则将其拆为两个部分)

    第一次接触Qt的Http项目,今天看了一下Post和Get的基本使用方法,就开始尝试了.原先以为Post专门用于向服务器发送请求,然后接收服务器应答的: 而Get只是单纯从服务器获取资源,比如下载这个 ...

  6. Codeforces 41D Pawn 简单dp

    题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...

  7. Android:自己定义输入法(输入password时防止第三方窃取)

    对于Android用户而言.一般都会使用第三方的输入法. 但是,在输入password时(尤其是支付相关的password),使用第三方输入法有极大的安全隐患. 眼下非常多网银类的APP和支付宝等软件 ...

  8. php5.3升级到5.5

    在网站中发布中: / 开启调试模式 建议开发阶段开启 部署阶段注释或者设为falsedefine('APP_DEBUG',true); true没问题,改为:false就报错 报错如下: PHP Fa ...

  9. 省份、城市、区县三级联动Html代码

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  10. Week8(10月31日):并发

    Part I:提问  =========================== 1. 更新关联.删除关联数据,需要注意哪些问题?以Instructor类为例说明. 2. 已知某请假系统,请实现以下界面的 ...