我有以下 JSON 输入 -
{"links":{"self":"/some/path"},"data": [{"type":"some_service","id":"foo","attributes": {"created":true ,"active":true,"suspended":false}}, {"type":"some_service","id":"dummy","attributes":{"created":false}}]}
我正在使用下面的代码 -
use strict;
use warnings;
use JSON::XS;
use Data::Dumper;
my $result = decode_json($input);
print Dumper($result) . "\n";
但我得到低于输出 -
$VAR1 = {
'data' => [
{
'attributes' => {
'active' => bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' ),
'created' => $VAR1->{'data'}[0]{'attributes'}{'active'},
'suspended' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' )
},
'id' => 'foo',
'type' => 'some_service'
},
{
'id' => 'dummy',
'attributes' => {
'created' => $VAR1->{'data'}[0]{'attributes'}{'suspended'}
},
'type' => 'some_service'
}
],
'links' => {
'self' => '/some/path'
}
};
看起来 'created' 中的值是 $VAR1->{'data'}[0]{'attributes'}{'active'} 这似乎不准确,并且在其他地方也发生了同样的情况。
我是否缺少代码中的某个地方或 JSON 输入有一些错误?请提供您的建议。