2013-10-31 42 views
0

下面是我想訪問的示例json代碼...此json實際上來自API。每當我複製並粘貼整個JSON以JSON lint..It說有效的JSON ..std :: class的對象無法轉換爲字符串

foreach ($movies as $movie) { 
echo "theaters ".var_dump($movie->release_dates->theater)"; 
} 

//Im actually trying to access a nested json in php... Something like 
{ 
"movies":[{ 
"tile":"Cowboys"; 
"release_dates":{"theater":"2013-11-29"}, 
so on.... 

每當我試着寫在它上面給我一個錯誤Object of stdclass cannot be converted to string ....或者,如果我寫

$x = json_decode(var_dump($movie->release_dates->theater), true)"; 
echo "theaters "$x[0]; 

它給像string[10]:2013-11-25 string[10]:2013-11-30輸出....所以on..What是錯誤....

+4

'var_dump'不返回任何東西,所以這是你想要什麼不清楚去做。 – Barmar

+0

要擴展@ Barmar的觀點,'var_dump'用於向您自己輸出調試信息,而不是解析JSON。 – Seventoes

+0

其實我想打印瓷磚,release_dates這個JSON響應來自一個API ..我用curl來發送請求和響應..我能夠通過循環打印瓷磚像上面的代碼一樣,像foreach($電影as $ movie){echo「$ movie-> tile」;}這是成功打印響應。 – user2779848

回答

0
$data = json_decode($movies, true); 

foreach ($data as $movie) { 
    echo "theaters ".implode(', ', $movie->release_dates->theater)"; 
} 
+0

看起來像你有一個未終止的字符串常量在那裏。 –

+0

它給出了一個錯誤,如json_decode將一個參數作爲字符串,數組給定 – user2779848