我想在 JSON 数据中获取游戏的 id、competitionId、competitionDisplayName。我当前的代码没有输出任何内容,谁能告诉我我做错了什么。谢谢$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 回答
偶然的你
TA贡献1841条经验 获得超3个赞
我检查了您的网址,游戏的数据是一个数组,因此您需要遍历它以获取每个游戏的值。
$array = json_decode($json);
foreach($array->games as $game){
$output = $game->competitionDisplayName;
prinr_r($output);
}
手掌心
TA贡献1942条经验 获得超3个赞
尝试这个:
<?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;
- 2 回答
- 0 关注
- 701 浏览
添加回答
举报
0/150
提交
取消