2016-09-14 39 views
1

PHP-> JSONPHP - > JSON響應,要按關鍵字過濾 - 500錯誤?

所以我打電話給一個在線服務,返回一個JSON我正在解碼。然後對於每條記錄,我是STRPOS對一個字段,如果!== FALSE,我希望它顯示記錄,否則轉到下一條記錄。

問題:沒有STRPOS,所有的代碼都可以工作,並且不會超時。用STRPOS,我得到了500錯誤。

它是我的代碼(效率低下)還是服務時間我可能?思考?

在此先感謝!

$jsonFile = file_get_contents('https://api.website.com/file.json'); 
$json_outputa = json_decode($jsonFile); 

foreach ($json_outputa->divisions as $division) 
{ 

$jsondeal = file_get_contents('https://api.website.com/specifics.json?division_id=' . $division->id . '&filters=category:' . $category . '&limit=20'); 

$jsondeal_output = json_decode($jsondeal); 

foreach ($jsondeal_output->deals as $deal) 
{ 
    If ($deal->tags) 
    { 
     If (strpos($deal->Title, $searchstring) !== false) 
     { 
      ?> 
        <tr> 
!! NOW DO STUFF !! 

*!該代碼工作並返回到用戶界面。只是刪除了STRPOS的IF。

$jsonFile = file_get_contents('https://api.website.com/file.json'); 
$json_outputa = json_decode($jsonFile); 

foreach ($json_outputa->divisions as $division) 
{ 

$jsondeal = file_get_contents('https://api.website.com/specifics.json?division_id=' . $division->id . '&filters=category:' . $category . '&limit=20'); 

$jsondeal_output = json_decode($jsondeal); 

foreach ($jsondeal_output->deals as $deal) 
{ 
If ($deal->tags) 
{ 
      ?> 
+0

它可能是有益的,看看什麼是工作,什麼樣的確切不同的代碼是沒有的。你是否用'true'來替換'strpos($ deal-> Title,$ searchstring)!== false'?你是否刪除了整個條件及其中的任何命令? –

+0

感謝您回覆@Patrick。代碼更改非常簡單,只需使用STRPOS刪除IF即可。見上面....(抱歉,沒有意識到我不能回到這裏)。 – GarageKid

+0

檢查你的錯誤日誌。狀態碼500幾乎總是伴隨着一個記錄錯誤。 –

回答

-1

我認爲它是你的鏈接在瀏覽器,它說,沒有發現404文件https://api.website.com/file.json 嘗試將其打開。

嘗試本地JSON或什麼有效的JSON文件中像這樣一個

http://www.json-generator.com/api/json/get/cbvSOJYRbC?indent=2

+0

是的,我更改了原始api地址, 。所以是的,它會爲你返回404。不是我。 :) – GarageKid

+0

噢好吧對不起,我的壞,我應該猜到了 –

+0

我有點困惑的條款返回true爲虛假的第一次出現?如果完全沒有發現不會是錯誤的正確答案? – GarageKid