2013-12-16 25 views
0

我有此刻的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 />"; 

我真的不現在這個問題是什麼,所以任何幫助會是gre在。

+0

這些函數從哪裏來?像getSystemHourAggregatedLoggedValues一樣,我沒有在PHP文檔中看到它是類成員 – user602525

+0

該函數來自webservices(.wsdl)。頂部的wsdl鏈接。它是SOAP API Web服務。 – Dainese

+0

https://api.netbiter.net/operation/v1/soap?wsdl – Dainese

回答

0

這個錯誤本身就是很有說明力的。它說你有一個stdObject和PHP不知道如何打印。

因爲你沒有給任何錯誤跟蹤,如果你是確保誤差從該行 echo "System $label : $value<br />";產生,那麼它的意思是說,的$label$value值是不正常的數據類型。它是一個un-named類的對象,它可能是即時生成的。

由於類,此對象包含可打印的字段。或者你可以爲這個類定義一個toString()方法,這樣php就可以使用這個方法來打印你的對象。

但很有可能您對此對象的fields感興趣。因此,您可以使用var_dump($label)print_r($label)查看此對象中包含的字段。然後你可以很容易地提取這些字段:echo $label->field1;