我正在尝试通过cURL集成游戏的API,我尝试使用您在下面看到的代码,但是,给了我错误
注意:尝试获取非对象的属性 第173行的C:\ xampp \ htdocs \ over \ index.php
JSON不是“数据”,我认为这让我感到困扰:
{"SoloKills": "494", "DamageDone": "758,071", "Eliminations": "1,911",}
$mode = "quick-play";
$allheroes = curl_init();
curl_setopt($allheroes, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($allheroes, CURLOPT_RETURNTRANSFER, true);
curl_setopt($allheroes, CURLOPT_FAILONERROR, true);
curl_setopt($allheroes, CURLOPT_URL,"https://api.lootbox.eu/{$platform}/{$country}/{$battletag}/quick-play/allHeroes/");
$result3 = curl_exec($allheroes);
curl_close($allheroes);
$stats3 = json_decode($result3, true);
foreach ($stats3 as $allhero)
{
$uccisioni = $allhero['Eliminations'];
echo $uccisioni;
}
答案 0 :(得分:0)
你没有关键的" ObjectiveKills"在这个JSON
{"SoloKills": "494", "DamageDone": "758,071", "Eliminations": "1,911"}
但我认为你可以得到" SoloKills"," DamageDone"," Eliminations"像:
foreach ($stats3 as $allhero) {
$uccisioni = $allhero['SoloKills'];
echo $uccisioni;
}
更新
你不需要在这里预约,我得到了
array(41) { ["SoloKills"]=> string(2) "55" ["ObjectiveKills"]=> string(3) "138" ...]}
您可以获得$ stats3 [' Eliminations']
答案 1 :(得分:0)
你必须在编码方面做得很好。它会对整个代码产生影响
"DamageDone": "758,071"不是
DamageDone": "758,071"
您已忘记引用标记!