json - Get request not the same decoded -
hi i'm new @ perl have few experience in other language. made simple code json file internet here telegram bot, when display got no probleme when decoded dedcode_json dont have @ same output :///
here output of server :
received reply: {"ok":true,"result":{"id":0000,"first_name":"[maga]"}}
and output of decoded anwser :
$var1 = { 'ok' => bless( do{\(my $o = 1)}, 'json::pp::boolean' ), 'result' => { 'id' => 0000, 'username' => 'maga_bot', 'first_name' => '[maga]' } };
how can 'result' part of decoded json ?
here code :
#!/usr/bin/perl use warnings; use lwp::useragent; use data::dumper; use json; $ua = lwp::useragent->new; $destination = "http://api.telegram.org/bot<token>/getme"; $req = http::request->new(get => $destination); $succes; $json; $resp = $ua->request($req); if ($resp->is_success) { $message = $resp->decoded_content; print "received reply: $message\n"; $succes = "yes"; $json = $message; } else { print "http post error code: ", $resp->code, "\n"; print "http post error message: ", $resp->message, "\n"; } print "encoding json file \n"; if ($succes eq "yes") { $decoded_json = decode_json($json); print dumper($decoded_json); } elsif ($succes ne "yes") { print "parsing json failed\n"; }
since decoded json converted perl hash reference in case, access such:
my $result = $decoded_json->{result}; print "$result->{first_name}\n";
output:
[maga]
Comments
Post a Comment