相关疑难解决方法(0)

通过perl解析用JSON编码的数组

我正在使用以下Perl代码使用该JSON模块解析JSON中的数组.但返回的数组长度为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";
Run Code Online (Sandbox Code Playgroud)

输出来了:

$VAR1 = [
     {
        'text' => 'text1',
        'name' => 'abc'
      },
      {
        'text' => 'text2',
        'name' => 'xyz'
      }
    ];
1
Run Code Online (Sandbox Code Playgroud)

perl json

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

json ×1

perl ×1