jellydeal
asked on
parse json with perl
Hi,
Im trying to parse some simple json with a perl script.
Heres the Json :
my perl errors with "NOT A HASH REFERENCE", I obviously have my code wrong, but cant find out how to fix it!
Heres my Code :
I understand I need to loop through the results and then display them individually but I cant figure out how :(
thank you
Im trying to parse some simple json with a perl script.
Heres the Json :
[
{
"to_user": "1234567",
"message": "test 1"
},
{
"to_user": "345456657",
"message": "test 2"
},
{
"to_user": "45667324",
"message": "test 3"
}
]
my perl errors with "NOT A HASH REFERENCE", I obviously have my code wrong, but cant find out how to fix it!
Heres my Code :
use HTTP::Request;
use LWP::UserAgent;
my $json = encode_json \%message;
my $uri = 'http://xxxx.com/server/imessage/get_messages.php';
my $req = HTTP::Request->new('POST', $uri);
$req->header( 'Content-Type' => 'application/json' );
$req->content( $json );
my $lwp = LWP::UserAgent->new;
$response = $lwp->request( $req );
if ($response->decoded_content ne "")
{
print "[$datestring] ";
my $decoded_json = decode_json($response->decoded_content);
print $decoded_json->{"to_user"} ; #ERROR line
}
I understand I need to loop through the results and then display them individually but I cant figure out how :(
thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER