As choroba noted, it looks like JSON. I took your sample data, closed the open structures (]}) and slurped it in using JSON. After looking at the data structure, I also added a little code to show how to access some of the individual elements.
#!/usr/bin/perl use strict; use warnings; use JSON; use Data::Dumper; # Read the JSON string & clean it up a little. You don't need this pa +rt, it's # only here to turn your sample into a text string. my $txt = join("", map { s/\s+$//; s{\\\\}{\\}g; $_ } <DATA>); #print $txt,"\n"; #print "-"x50,"\n"; # Create JSON parser and decode the string my $json = JSON->new->allow_nonref; $json = $json->relaxed(1); my $r = $json->decode($txt); # Dump the decoded data to the screen so we can see how to access the +bits #print Dumper($r); # Dump some of the bits: print "RESPONSE STATUS: ", $r->{meta}{status}, "=", $r->{meta}{msg}, " +\n"; for my $item (@{ $r->{response} }) { print "BLOG NAME: ", $item->{blog_name}, ", DATE:", $item->{date}, + "\n"; } __DATA__ {"meta":{"status":200,"msg":"OK"},"response":[{"blog_name":"wmr101","i +d":698 95404084,"post_url":"http:\\/\\/wmr101.tumblr.com\\/post\\/69895404084 +\\/while-read- stdin-2048-a-29-b-73-c-142-t","slug":"while-read-stdin-2048-a-29-b-73- +c-142-t","type ":"quote","date":"2013-12-13 18:18:57 GMT","timestamp":1386958737,"sta +te":"published ","format":"html","reblog_key":"KEalDhb2","tags": ["perl"],"short_url":"http:\\/\\/tmblr.co\\/ZQJ0Ox1165peq","highlight +ed":[],"note_cou nt":0,"text":"$_=’while(read+STDIN,$_,2048){$a=29;$b=73;$c=142;$t=255; +@t=map{$_%16or $t^=$c^=($m=(11,10,116,100,11,122,20,100)[$_\\/16%8])&110;$t^=(72,@z=( +64,72,$a^=12*( $_%16-2?0:$m&17)),$b^=$_%64?12:0,@z)[$_%8]}(16..271);if((@a=unx”C*”,$_ +)[20]&48){$h== 5;$_==unxb24,join”“,@b=map{xB8,unxb8,chr($_^$a[—$h+84])}@ARGV;s\\/…$\\ +/1$&\\/;$d=unx V,xb25,$_;$e=256|(ord$b[4])>8^($f=$t&($d»12^$d»4^$d^$d\\/8))>8^($t&($g +=($q=$e»14&7^$ e)^$q*8^$q>=8)+=$f+(~$g&$t))for@a[128..$#a]}print+x”C*”,@a}’;s\\/x\\/p +ack+\\/g;eval" ,"source":""}, {"blog_name":"a0001","id":69691252013,"post_url":"http:\\/\\/a0001.tu +mblr.com\\/post\ \/69691252013\\/perl","slug":"perl","type":"text","date":"2013-12-11 1 +4:48:03 GMT"," timestamp":1386773283,"state":"published","format":"html","reblog_key" +:"Lhh9Osdt","t ags":["perl"],"short_url":"http:\\/\\/tmblr.co\\/ZSfAvp10vx1qj","highl +ighted":[],"no te_count":0,"title":"perl\\u3067\\u30d5\\u30a1\\u30a4\\u30eb\\u3092\\u +8aad\\u307f\\u 8fbc\\u3080","body":"\\u003Cp\\u003E\\u30d5\\u30a1\\u30a4\\u30eb\\u30a +a\\u30fc\\u30d 7\\u30f3\\u3001\\u3088\\u304f\\u4f7f\\u3046\\u306e\\u3067\\u66f8\\u304 +4\\u3066\\u307 f\\u307e\\u3057\\u305f\\u3002\\u003C\\/p\\u003E\\n\\u003Cpre class=\\u +0022brush:perl ;\\u0022\\u003E open $FH, \\u0022hoge.txt\\u0022 or die $!;\\n while ( + readline $FH ) {\\n # \\u51e6\\u7406 \\n }\\n clise $FH;\\n\\u003C\\/pre\\u003E\\n\ +\u003Cp\\u003E or\\u6f14\\u7b97\\u5b50\\u306f\\u5de6\\u8fba\\u3092\\u8a55\\u4fa1\\u30 +57\\u3066\\u30 02\\u7d50\\u679c\\u304c\\u507d\\u306e\\u5834\\u5408\\u306f\\u003C\\/p\ +\u003E\\n\\u00 3Cp\\u003E\\u53f3\\u8fba\\u3092\\u5b9f\\u884c\\u3057\\u307e\\u3059\\u3 +002\\u3053\\u3 06e\\u5834\\u5408\\u306f\\u30d5\\u30a1\\u30a4\\u30eb\\u30aa\\u30fc\\u3 +0d7\\u30f3\\u3 04c\\u5931\\u6557\\u3059\\u308b\\u3068\\u003C\\/p\\u003E\\n\\u003Cp\\u +003Eundef\\u30 4c\\u8fd4\\u308a\\u3001undef\\u306ffalse\\uff08\\u507d\\uff09\\u6271\\ +u3044\\u306a\\ u306e\\u3067\\u003C\\/p\\u003E\\n\\u003Cp\\u003Edie\\u95a2\\u6570\\u30 +92\\u5b9f\\u88 4c\\u3057\\u3066\\u30d7\\u30ed\\u30b0\\u30e9\\u30e0\\u304c\\u7d42\\u4e +86\\u3057\\u30 7e\\u3059\\u3002\\u003C\\/p\\u003E\\n\\u003Cp\\u003E\\u305d\\u306e\\u3 +068\\u304d$!\\ uff1d\\u30a8\\u30e9\\u30fc\\u30e1\\u30c3\\u30bb\\u30fc\\u30b8\\u304c\\ +u6a19\\u6e96\\ u51fa\\u529b\\u306b\\u8868\\u793a\\u3055\\u308c\\u307e\\u3059\\u3002\\ +u003C\\/p\\u00 3E\\n\\u003Cp\\u003E\\u3081\\u3067\\u305f\\u304f\\u6210\\u529f\\u3057\ +\u305f\\u3068\ \u304d\\u306fwhile( readline $FH )\\u306b\\u9032\\u307f\\u307e\\u3059\\u3002\\u003C\\/p\\u003E\\n\\u0 +03Cp\\u003Ereadl ine\\u3067\\u30d5\\u30a1\\u30a4\\u30eb\\u306e\\u5185\\u5bb9\\u3092\\u4 +e00\\u884c\\u3 05a\\u3064\\u53d6\\u5f97\\u3057\\u3066\\u003C\\/p\\u003E\\n\\u003Cp\\u +003E\\u4f55\\u 304b\\u3057\\u3089\\u51e6\\u7406\\u3067\\u304d\\u307e\\u3059\\u3002\\u +53d6\\u5f97\\u 3057\\u305f\\u5185\\u5bb9\\u306f$_\\u306b\\u5165\\u3063\\u3066\\u307e\ +\u3059\\u30fc\ \u3002\\u003C\\/p\\u003E\\n\\u003Cp\\u003E\\u003Ca href=\\u0022http:\\ +/\\/www.perlpl us.jp\\/perl\\/file\\/index3.html\\u0022 target=\\u0022_blank\\u0022\\ +u003Ehttp:\\/\ \/www.perlplus.jp\\/perl\\/file\\/index3.html\\u003C\\/a\\u003E\\u003C +\\/p\\u003E"}, ]}
When you run it, it gives:
$ perl ex_json.pl RESPONSE STATUS: 200=OK BLOG NAME: wmr101, DATE:2013-12-13 18:18:57 GMT BLOG NAME: a0001, DATE:2013-12-11 14:48:03 GMT
You'll notice a couple lines of code commented out. They're what I used when debugging the example.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: Extracting data from api response..
by roboticus
in thread Extracting data from api response..
by JackPerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |