1

I want to get id,competitionId,competitionDisplayName of games in the JSON data.My current code doesn't output anything could any one tell me what i am doing wrong.Thanks

$json_string = 'https://webws.365scores.com/web/games/?langId=27&timezoneName=Asia/Hebron&userCountryId=-1&appTypeId=5&sports=1&startDate=17/08/2019&endDate=17/08/2019';
$json = file_get_contents($json_string);
$array = json_decode($json);

foreach($array as $values)
{
    $output = $values->games['competitionDisplayName'] . "\n";
}

echo $output;

2 Answers2

1

I checked your url, the data coming in for games is an array, so you need to loop through that to get the values of each game.

$array = json_decode($json);

foreach($array->games as $game){
    $output = $game->competitionDisplayName;
    prinr_r($output);
}
Prateek
  • 834
  • 9
  • 28
1

Try this:

<?php

$json_string = 'https://webws.365scores.com/web/games/?langId=27&timezoneName=Asia/Hebron&userCountryId=-1&appTypeId=5&sports=1&startDate=17/08/2019&endDate=17/08/2019';
$json = file_get_contents($json_string);

$result = json_decode($json);

foreach ($result->games as $game) {
   $output .= $game->competitionDisplayName . "\n";
}

echo $output;
odan
  • 4,757
  • 5
  • 20
  • 49