Catchable fatal error: in json_decode

Catchable fatal error: in json_decode

我想消除 JSON 视图格式和 return 带逗号的字符串数据。

当我使用 json_decode($row['test_row']) 时,它 return 就是我

Catchable fatal error: Object of class stdClass could not be converted to string in C

<?php 
try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password );    
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = 'SELECT * FROM database.test;' ;
        $get_all_data = $conn->prepare($sql);
        $get_all_data -> execute(array($sql));
        $all_row = $get_all_data->fetch(PDO::FETCH_ASSOC); 
        $all = $all_row;
    }
   catch(PDOException $e)
         {
           echo $sql . "<br>" . $e->getMessage();
         }

这里是table,table头:

    echo "<tbody>";
    echo "<table>";
          $conn = null;   
    while($row = $get_all_data->fetch(PDO::FETCH_ASSOC)) 
{   

echo "<tr>  
       <td>" . json_decode($row['my_data']) . "</td> 
      </tr>";  
} 
    echo "</tbody>";
    echo "</table>";  ?>

如果我让 $row['my_data'],它 return 以 JSON 格式

向我提供来自数据库的数据

json_decode returns PHP 对象,然后您尝试使用 echo 将其打印为字符串。这是抛出此错误。

您必须使用 implode 或此类函数将其设为逗号分隔的字符串。以后肯定能用。

因为我不知道 $row['my_data'] 的值所以可以建议你确切的代码。