hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at get_f5_pool_member_object_status.pl line 50.
push @out,[@tmp];
};
print encode_json(@out);
perl 2维数组,转成json格式
encode_json 需要一个hash 或者数组引用
一维数组json:
[root@yyjk tmp]#cat t1.pl
use JSON qw/encode_json decode_json/;
my @a=(1,2,3,4);
print @a;
print "
";
print encode_json(@a);
print "
";
[root@yyjk tmp]#perl t1.pl
1234
hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at t1.pl line 5.
[root@yyjk tmp]#cat t1.pl
use JSON qw/encode_json decode_json/;
my @a=(1,2,3,4);
print @a;
print "
";
print encode_json(@a);
print "
";
[root@yyjk tmp]#perl t1.pl
1234
[1,2,3,4]
[root@yyjk tmp]
2维数组:
这种变成一维数组了
use JSON qw/encode_json decode_json/;
my @a=((1,2,3,4),(6,7,8,9));
print @a;
print "
";
print encode_json(@a);
print "
";
[root@yyjk tmp]#perl t1.pl
12346789
[1,2,3,4,6,7,8,9]
[root@yyjk tmp]#cat t1.pl
use JSON qw/encode_json decode_json/;
my @a=([1,2,3,4],[6,7,8,9]);
print @a;
print "
";
print encode_json(@a);
print "
";
[root@yyjk tmp]#perl t1.pl
ARRAY(0x2351160)ARRAY(0x2365778)
[[1,2,3,4],[6,7,8,9]]