如何解析{“ access_token”:“ Abcd45689012031”}

时间:2019-02-28 10:17:03

标签: perl

我该如何解析。输入= {“ access_token”:“ Abcd45689012031”},输出=“ Abcd45689012031”

2 个答案:

答案 0 :(得分:1)

看起来像JSON。因此,请使用JSON解析器:

#!/usr/bin/perl
use warnings;
use strict;

use JSON;

my $json = JSON->new;
my $object = $json->decode('{"access_token":"Abcd45689012031"}')
    or die "JSON\n";

print $object->{access_token}, "\n";

exit 0;

试运行:

$ perl dummy.pl
Abcd45689012031

答案 1 :(得分:0)

使用JSONJSON::XS甚至Cpanel::JSON::XS来解析JSON:

use JSON::XS qw{ decode_json };

my $input = '{"access_token":"Abcd45689012031"}';
my $json  = decode_json($input);
my $token = $json->{access_token};