stdClass类的对象无法在中转换为字符串


Object of class stdClass could not be converted to string in

我现在PHP有问题,我收到了这个错误,

stdClass类的对象无法转换为字符串,当我在我的站点中运行这部分代码时发生错误

<?php
//Setup
$wsdl='https://api.netbiter.net/operation/v1/soap?wsdl';
$client=new SoapClient ($wsdl);
$accessKey='042B79FC23AB0925D4D20FBB8EE42B98';  //Replace by your access key
$systemId='003011FB506F'; //Replace by your system id
$parameterId='17379.0.44535'; //Replace by your data logging id
$limitRows='24'; //How many hour data logging
$sortOrder='desc'; //Order of the response list
$startDate='2013-12-04T03:00:00Z'; //The UTC start date and time limit for the list
$endDate='2013-12-05T03:00:00Z'; //The UTC end date and time limit for the list
?>
<?php
function handleArgosException(Exception $fault)
{
   echo "Error: ";
   echo "Message: {$fault->faultstring} ";
   if (isset($fault->detail->ForbiddenException))
   {
      echo "Forbidden exception: Code {$fault->detail->ForbiddenException->code}";
   }
   else if (isset($fault->detail->LimitException))
   {
      echo "Limit exception: Code {$fault->detail->LimitException->code}";
   }
   else if (isset($fault->detail->GeneralException))
   {
      echo "General exception: Code {$fault->detail->GeneralException->code}";
   }
}
?>
<?php
echo "<h1>Test Data Logging</h1>";
$param=array ('accessKey'=>$accessKey, 'systemId'=>$systemId, 'parameterId'=>$parameterId,
              'limitRows'=>$limitRows, 'sortOrder'=>$sortOrder, 'startDate'=>$startDate,
              'endDate'=>$endDate);
try
{
   $resSystems = $client->getSystemHourAggregatedLoggedValues($param);
}
catch (SoapFault $fault)
{
   handleArgosException($fault);
}
echo "<h2>Example code</h2>";
foreach($resSystems->HourAggregatedLogParameters as $label => $value)
{
   echo "System $label : $value<br />";
}
?>

发生错误的行是这一行,

echo "System $label : $value<br />";

我现在真的不知道这个问题是什么,所以任何帮助都会很棒。

这个错误本身就很容易解释。据说你有一个stdObject,php不知道如何打印它。

由于您没有给出任何错误跟踪,如果您确信错误是从这一行生成的echo "System $label : $value<br />";,那么这意味着,$label$value的值不是正常的数据类型。它是一个un-named类的对象,可能是动态生成的。

由于是一个类,此对象包含可以打印的字段。或者,您可以为这个类定义一个toString()方法,以便php可以使用这个方法打印您的对象。

但你很可能对这个物体的fields感兴趣。因此,您可以执行var_dump($label)print_r($label)来查看此对象中包含哪些字段。然后您可以很容易地提取这些字段,如下所示:echo $label->field1;