我需要處理空JSON請求,以防萬一用戶出錯。如何處理來自JSON的空數據
這裏是我的代碼:
$JSON = file_get_contents($url);
//Puts the JSON var into a parameter that actually does the decoding into JSON
$data = json_decode($JSON,true);
echo $JSON;
if ($JSON === ''){
header("Location: contact2.php");
}else{
//Execute the original plan
}
這裏是如果,不幸的是有沒有爲我工作報表的樂趣陣列:
if(is_array($data))
if($JSON === null)
if($data === null)
不勝感激任何幫助。
解釋爲什麼它沒有工作。任何eny錯誤消息? –
我對PHP相對來說比較新,如果我已經或者知道一個像樣的IDE和一個調試器,我總體上會更快樂一點,但問題會更少。從我的低估中,json_decode方法將其引入數組中。當我故意撞毀它時,我感到驚訝的是is_array方法對我不起作用。 – user3124081