std :: class的对象不能转换为字符串

时间:2013-10-31 18:09:31

标签: php echo json var-dump

下面是我想要访问的示例json代码...这个json实际上来自API。每当我在json lint中复制并粘贴整个json时..它说有效的json ..

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的输出......所以......错误是什么......

1 个答案:

答案 0 :(得分:0)

$data = json_decode($movies, true);

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