in reply to JSON ARRAY Problem
You should decode the JSON so you could interact with the data as Perl structures:
use JSON; my $json = <<HERE; {"id":241995,"name":"Georgia vs Finland","start":"2013-09-10T17:00:00. +000Z","status":"paid","sport-id":15,"category-id":[146598],"markets": +[],"meta-tags":[{"id":4,"name":"Soccer","type":"SPORT"},{"id":650,"na +me":"Qualifiers","type":"COMPETITION"},{"id":5,"name":"World Cup 2014 +","type":"COMPETITION"},{"id":1,"name":"Sport","type":"Root"},{"id":6 +51,"name":"September 10th 2013","type":"DATE"}],"in-running-flag":fal +se,"allow-live-betting":false} HERE my $data = decode_json($json); my @meta_tag_ids = map { $_->{id} } @{ $data->{meta_tags} };
EDIT: Actually, maybe I understand the problem now...you only want the IDs of the metatags that display the sport being played and the date the sport was played on, correct?
use JSON; my $json = <<HERE; {"id":241995,"name":"Georgia vs Finland","start":"2013-09-10T17:00:00. +000Z","status":"paid","sport-id":15,"category-id":[146598],"markets": +[],"meta-tags":[{"id":4,"name":"Soccer","type":"SPORT"},{"id":650,"na +me":"Qualifiers","type":"COMPETITION"},{"id":5,"name":"World Cup 2014 +","type":"COMPETITION"},{"id":1,"name":"Sport","type":"Root"},{"id":6 +51,"name":"September 10th 2013","type":"DATE"}],"in-running-flag":fal +se,"allow-live-betting":false} HERE my $data = decode_json($json); my @interesting_meta_tag_ids = (); foreach my $metatag (@{ $data->{meta_tags} }) { my $type = $metatag->{type}; if ($type eq 'SPORT' or $type eq 'DATE') { push @interesting_meta_tag_ids, $metatag->{id}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: JSON ARRAY Problem
by davido (Cardinal) on Sep 30, 2013 at 23:50 UTC | |
by Riales (Hermit) on Oct 01, 2013 at 04:43 UTC | |
by davido (Cardinal) on Oct 01, 2013 at 05:28 UTC |