JSON数据输出

时间:2014-11-04 12:09:32

标签: json perl

以下是具有JSON数据的Perl代码:

use Data::Dumper;
use JSON;

my $var = '{

    "episode1": {
      "title":"Cartman Gets an Anal Probe",
      "id":"103511",
      "airdate":"08.13.97",
      "episodenumber":"101",
      "available":"true",
      "when":"08.13.97"
    }
  },
  {
    "episode2": {
      "title":"Weight Gain 4000",
      "id":"103516",
      "airdate":"08.20.97",
      "episodenumber":"102",
      "available":"true",
      "when":"08.20.97"
    }
}';

my $resp = JSON::jsonToObj( $var );

print Dumper ($resp);

输出结果为:

$VAR1 = {
  'episode1' => {
    'when' => '08.13.97',
    'episodenumber' => '101',
    'airdate' => '08.13.97',
    'title' => 'Cartman Gets an Anal Probe',
    'id' => '103511',
    'available' => 'true'
  }
};

我正在转储JSON数据,但只有episode1被转储到输出中。但是,我希望在转储时显示episode1episode2。怎么做?

1 个答案:

答案 0 :(得分:2)

编写有效的JSON。

来自JSON Lint

Parse error on line 14:
...: "08.13.97"    }},{    "episode2": 
---------------------^
Expecting 'EOF'

如果您想要一个对象数组,则需要数据中的数组:[...]