这是我的子程序:
my $json = JSON->new;
my $decoded_json = from_json( $response->decoded_content, { utf8 => 1 } );
print Dumper($decoded_json->{"response"}->{"recs"}->{"objs"}, length($decoded_json->{"response"}->{"recs"}->{"objs"})) . "\r\n";
foreach($decoded_json->{"response"}->{"recs"}->{"objs"}) {
# need to get name..
#print Dumper($_, length($_)) . "\r\n";
}
我正在从一个网站(实际上是 CloudFlare)获取 JSON 并尝试解析数据。这是 JSON 的一个示例。我试图从每个结果中获取“名称”,如果“名称”是我想要的,我将获得另一个字段。
'response' => {
'recs' => {
'count' => 4,
'has_more' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),
'objs' => [
{# <-- these
'ttl_ceil' => 86400,
'ttl' => '1',
'content' => '[SNIPPED]',
'zone_name' => 'xyz.info',
'display_content' => '[SNIPPED]',
'ssl_status' => undef,
'name' => 'xyz.info',
'prio' => undef,
'auto_ttl' => 1,
'display_name' => 'xyz.info',
'props' => {
'pending_ssl' => 0,
'cf_open' => 0,
'proxiable' => 1,
'expired_ssl' => 0,
'ssl' => 0,
'vanity_lock' => 0,
'expiring_ssl' => 0,
'cloud_on' => 1
},
'rec_tag' => '[SNIPPED]',
'rec_id' => '[SNIPPED]',
'type' => 'A',
'ssl_id' => undef,
'ssl_expires_on' => undef,
'service_mode' => '1'
},
{ # < -- these
'ttl_ceil' => 86400,
'ttl' => '1',
'content' => '0.0.0.0',
'zone_name' => 'xyz.info',
'display_content' => '0.0.0.0',
'ssl_status' => undef,
'name' => 'zzz.xyz.info',
'prio' => undef,
'auto_ttl' => 1,
'display_name' => 'zzz',
'props' => {
'pending_ssl' => 0,
'cf_open' => 0,
'proxiable' => 1,
'expired_ssl' => 0,
'ssl' => 0,
'vanity_lock' => 0,
'expiring_ssl' => 0,
'cloud_on' => 1
},
'rec_tag' => '[SNIPPED]',
'rec_id' => '[SNIPPED]',
'type' => 'A',
'ssl_id' => undef,
'ssl_expires_on' => undef,
'service_mode' => '1'
},
},
'result' => 'success'
};