0

我的perl代码:

#!/usr/bin/perl

if ( not -f "$ARGV[0]" ) { die "$!"; }

open(DATA,"$ARGV[0]") || die "$!";
$data = <DATA>;
close(DATA);

use JSON qw(decode_json);
$tidy = decode_json($data);

use Data::Dumper;
$Data::Dumper::Terse = 1;
#$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;

print Dumper $tidy;

我的 JSON 数据:

[{"n":"v8_skillgames","i":"m1QhFLZ2CI","s":21254,"t":1522783462114739392,"m":false},{"n":"v8_breakaway","i":"kpOIPLacEa","s":6163,"t":1522783462115880128,"m":false}]

意外输出:

[
  {
    'i' => 'm1QhFLZ2CI',
    'm' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
    'n' => 'v8_skillgames',
    's' => 21254,
    't' => '1522783462114739392'
  },
  {
    'i' => 'kpOIPLacEa',
    'm' => $VAR1->[0]{'m'},
    'n' => 'v8_breakaway',
    's' => 6163,
    't' => '1522783462115880128'
  }
]

我编写了一些 perl 脚本来解析单行 JSON 数据。但我得到了关于“m”的意外输出。怎么了?

4

1 回答 1

1

我在谷歌搜索并找到了解决方案:

use JSON::PP qw(decode_json);
$JSON::PP::true  = 'true';
$JSON::PP::false = 'false';
于 2018-04-04T20:08:06.617 回答