所以现在我正在通过这个请求从json API(battle.net)中提取数据
https://us.api.battle.net/wow/realm/status?locale=en_US&realms=runetotem&apikey=xxxxxxxxxxxxxxx
API密钥被故意隐藏,这将返回以下内容
{
"realms": [{
"type": "pve",
"population": "medium",
"queue": false,
"wintergrasp": {
"area": 1,
"controlling-faction": 1,
"status": 0,
"next": 1433468324674
},
"tol-barad": {
"area": 21,
"controlling-faction": 1,
"status": 2,
"next": 1433465638814
},
"status": true,
"name": "Runetotem",
"slug": "runetotem",
"battlegroup": "Vengeance",
"locale": "en_US",
"timezone": "America/Los_Angeles",
"connected_realms": ["uther", "runetotem"]
}]
}
我正在使用php将其放入数组中,然后尝试在if语句中调用来自该数组的值,但是if语句对于我的检查始终为true。我根本不理解为什么,如果有人可以帮助的话,那太好了。下面的代码。
<?php
$json_url = "https://us.api.battle.net/wow/realm/status?locale=en_US&realms=runetotem&apikey=xxxxxxxxxxx";
$json = file_get_contents($json_url);
$data = json_decode($json, TRUE);
?>
<tr class="latestthreads_portal">
<td width="230px" class="trow3">
<strong>Realm Status</strong>
<span class="smalltext"><br />
<?php if ($data['realms'][0]['status'] == 2)
{
echo "up";
}
else{
echo "Down?";
}
?>
<br />
<br /> <div class="border"></div>
</span>
</td>
</tr>
请赶紧原谅糟糕的格式。
我认为您有比较问题和数据嵌套问题。它看起来像你对我都比较if (2 == true)
它的值应该true
在PHP。http://php.net/manual/zh/types.comparisons.php
另外,您仅检查“领域”数组的状态,而不检查“ toll-barad”和“ wintergrasp”对象的状态,不确定确切地想要什么。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句