Php 类stdClass的对象无法转换为中的字符串
我现在在PHP上遇到了一个问题,我得到了这个错误 类stdClass的对象无法转换为字符串在我的站点中运行这部分代码时出错Php 类stdClass的对象无法转换为中的字符串,php,api,soap,wsdl,Php,Api,Soap,Wsdl,我现在在PHP上遇到了一个问题,我得到了这个错误 类stdClass的对象无法转换为字符串在我的站点中运行这部分代码时出错 <?php //Setup $wsdl='https://api.netbiter.net/operation/v1/soap?wsdl'; $client=new SoapClient ($wsdl); $accessKey='042B79FC23AB0925D4D20FBB8EE42B98'; //Replace by your access key $syst
<?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 />";
echo“系统$label:$value
”;
我现在真的不知道这个问题是什么,所以任何帮助都是很好的。这个错误本身就是很好的解释。它说您有一个
stdObject
,php不知道如何打印它
由于您没有给出任何错误跟踪,如果您确定错误是从此行生成的
echo“系统$label:$value
”
,那么它的意思是,$label
或$value
的值不是正常的数据类型。它是一个未命名的类的对象,可能是动态生成的
由于该对象是一个类,因此它包含可以打印的字段。或者您可以为此类定义一个toString()
方法,以便php可以使用此方法打印您的对象
但您很可能对该对象的字段
感兴趣。因此,您可以执行var\u dump($label)
或print\r($label)
以查看此对象中包含哪些字段。然后您可以很容易地提取如下字段:echo$label->field1代码>这些函数来自哪里?像getSystemHouragGregatedLoggedValue一样,我不认为作为PHP文档中的类成员,函数来自webservices(.wsdl)。wsdl链接位于顶部。这是SOAP API webservices。如果您使用var_dump($resSystems->houraggegatedLogParameters),它会对对象说些什么?很明显,当您通过echoi将此对象更改为“转换为字符串”时,您得到的对象没有可用的_toString()。是否正确?foreach(var_dump($resSystems->houraggegatedlogparameters)作为$label=>$value)