Created
October 28, 2012 23:55
-
-
Save onevcat/3970516 to your computer and use it in GitHub Desktop.
Perl_JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use JSON; | |
use Encode 'from_to'; | |
# 假设$json是GBK编码的 | |
my $json = '{"test" : "我是GBK编码的哦"}'; | |
from_to($json, 'GBK', 'UTF-8'); | |
my $data = decode_json($json); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use utf8; | |
use Encode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $array = decode_json($json_out); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use JSON qw/encode_json decode_json/; | |
my $data = [ | |
{ | |
'name' => 'Ken', | |
'age' => 19 | |
}, | |
{ | |
'name' => 'Ken', | |
'age' => 25 | |
} | |
]; | |
my $json_out = encode_json($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment