Gruaig has asked for the wisdom of the Perl Monks concerning the following question:
Hi Im trying to extract data from a node the json is styled as follows
{"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,"name":"Qualifiers","type":"COMPETITION"},{"id":5,"name":"World Cup 2014","type":"COMPETITION"},{"id":1,"name":"Sport","type":"Root"},{"id":651,"name":"September 10th 2013","type":"DATE"}],"in-running-flag":false,"allow-live-betting":false}The information I am trying to extract is in the meta-tag array the node which has the date and sports name in it.
So {"id":5,"name":"World Cup 2014","type":"COMPETITION"},{"id":651,"name":"September 10th 2013","type":"DATE"}The problem is which each new api call the contents of the array change positions so if the information I wanted was in position [0] it may have moved to 3.
17 my @metatag = (); 18 19 for my $i (0..3){ 20 21 my $var1 = $decoded->{'meta-tags'}[$i]{'id'}; 22 if($var1 =~ m/([0-9a-zA-Z]{9})/ ){ 23 push @metatag => $var1; 24 my $compid = $var1; 25 $i++;
I came up with this to extract the ID tag its a horrible hack. Anyone know how I can extract the correct data everytime.?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: JSON ARRAY Problem
by Riales (Hermit) on Sep 30, 2013 at 22:21 UTC | |
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 | |
|
Re: JSON ARRAY Problem
by aaron_baugher (Curate) on Sep 30, 2013 at 22:13 UTC | |
|
Re: JSON ARRAY Problem (category of type of id is named)
by Anonymous Monk on Oct 01, 2013 at 00:07 UTC | |
|
Re: JSON ARRAY Problem
by kcott (Archbishop) on Oct 01, 2013 at 13:55 UTC | |
|
Re: JSON ARRAY Problem
by Gruaig (Initiate) on Oct 16, 2013 at 16:06 UTC |