frank1 has asked for the wisdom of the Perl Monks concerning the following question:
I have the following json message, am getting results, am getting 1 team instead of all, i want to get all teams
teams are enclosed by curly braces in
"teams":[ {}, #team {} # another team ],
{ "sports": [ { "id": "600", "leagues": [ { "id": "700", "teams": [ { "team": { "id": "331", "name": "Brighton & Hove Albion", "isAllStar": false, "logos": [ { "alt": "", "rel": [ "full", "default" ], "width": 500, "height": 500 }, { "alt": "", "rel": [ "full", "dark" ], "width": 500, "height": 500 } ], "links": [ { "language": "en-US", "rel": [ "clubhouse", "desktop", "team" ], "text": "Clubhouse" }, { "language": "en-US", "rel": [ "stats", "desktop", "team" ], "text": "Stats" }, { "language": "en-US", "rel": [ "schedule", "desktop", "team" ], "text": "Fixtures" } ] } }, { "team": { "id": "380", "name": "Wolverhampton Wanderers", "isAllStar": false, "logos": [ { "alt": "", "rel": [ "full", "default" ], "width": 500, "height": 500 }, { "alt": "", "rel": [ "full", "dark" ], "width": 500, "height": 500 } ], "links": [ { "language": "en-US", "rel": [ "clubhouse", "desktop", "team" ], "text": "Clubhouse" }, { "language": "en-US", "rel": [ "stats", "desktop", "team" ], "text": "Stats" }, { "language": "en-US", "rel": [ "schedule", "desktop", "team" ], "text": "Fixtures" } ] } } ], "year": 2025, "season": { "year": 2025, "displayName": "2025" } } ] } ] }
this is my code
for my $match (@{$parse_json->{sports}}) { my $teamname = $match->{leagues}[0]{teams}[0]{team}{name}; $Response_tmlist .= $teamname; print $Response_tmlist; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: parse out json message
by 1nickt (Canon) on Sep 15, 2025 at 21:29 UTC | |
by frank1 (Monk) on Sep 15, 2025 at 22:02 UTC | |
Re: parse out json message
by hippo (Archbishop) on Sep 15, 2025 at 16:50 UTC | |
by frank1 (Monk) on Sep 15, 2025 at 18:56 UTC | |
by Corion (Patriarch) on Sep 15, 2025 at 19:50 UTC | |
by frank1 (Monk) on Sep 15, 2025 at 20:22 UTC |