CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [robertico] Parse JSON with PERL: Edit Log



Zhris
Enthusiast

Mar 21, 2013, 1:57 PM


Views: 733
Re: [robertico] Parse JSON with PERL

Hi,

Use JSON from CPAN:


Code
#!/usr/bin/perl 
use strict;
use warnings FATAL => qw/all/;
use JSON;
use Data::Dumper;

my $json_string = '{"to_id": 0, "message": "This is a sample", "message_id": 1000, "from_id": 999}';

my $json_object = JSON->new( );

my $perl_ref = $json_object->decode( $json_string );

print Dumper( $perl_ref );


Output:

Code
$VAR1 =  
{
'from_id' => 999,
'message_id' => 1000,
'to_id' => 0,
'message' => 'This is a sample'
};


Chris


(This post was edited by Zhris on Mar 21, 2013, 1:59 PM)


Edit Log:
Post edited by Zhris (Enthusiast) on Mar 21, 2013, 1:59 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives