【发布时间】:2011-04-11 08:10:43
【问题描述】:
我正在使用以下 Perl 代码来解析 JSON 中的数组,使用 JSON module。但是返回的数组长度为 1,我无法正确迭代它。所以问题是我无法使用返回的数组。
#!/usr/bin/perl
use strict;
my $json_text = '[ {"name" : "abc", "text" : "text1"}, {"name" : "xyz", "text" : "text2"} ]';
use JSON;
use Data::Dumper::Names;
my @decoded_json = decode_json($json_text);
print Dumper(@decoded_json), length(@decoded_json), "\n";
输出来了:
$VAR1 = [
{
'text' => 'text1',
'name' => 'abc'
},
{
'text' => 'text2',
'name' => 'xyz'
}
];
1
【问题讨论】: