2014-07-18 195 views
0

嘿,我一直在努力,DECODE這樣我的JSON數據: `無效參數

$json = file_get_contents("http://localhost/php/service.php?rquest=searcht&user=".$user); 
$final_res = html_entity_decode($json); 
foreach ($final_res as $thedata->user) 
      { 
      foreach ($thedata as $value) { ?> 
      <tr> 
      <td ><? echo $value['No']?> </td> 
      <td><?echo $value['user']?></td> 
    } 
} 

` 解碼數據正常工作與輸出JSON,但是當我試圖foreach的JSON數據,它does not工作,但..在其他情況下,我用這種foreach以相同的方式打印我的數據與選擇*數據查詢到其他頁面。它的工作,但我使用這種foreach以相同的方式,但輸出爲foreach()提供的無效參數請告訴我,如果我犯了一個錯誤...

+0

嘗試使用var_dump()來查看傳遞給foreach()循環的參數的數據類型。 –

+0

你在哪裏解碼json?它根本沒有調用json_decode。 –

+0

更新我一直在這樣解碼:$ final_res = html_entity_decode($ json); $ final_res1 = json_decode(stripslashes($ final_res));但foreach不起作用 – user3511548

回答

0

你還沒有使用json_decode,你得到的內容file_get_contents是一個字符串,應用json_decode($final_res)以獲得數組形式的內容。

+0

$ final_res = html_entity_decode($ json);我解碼它在那裏,我嘗試使用json_decode但輸出爲NULL ... – user3511548

+0

更新我解碼這樣的數據: $ final_res = html_entity_decode($ json); \t \t \t $ final_res1 = json_decode(stripslashes($ final_res)); – user3511548

+0

更新我一直在解碼我的數據李這: $ final_res = html_entity_decode($ json); $ final_res1 = json_decode(stripslashes($ final_res));但是foreach不起作用 – user3511548