[英]php error : Trying to get property of non-object
無法處理此錯誤,因為我在此處輸入代碼時收到此錯誤
注意:第161行嘗試獲取C:\\xampp\\htdocs\\seo\\seo.php中非對象的屬性 注意:嘗試獲取C:\\xampp\\htdocs\\seo\\seo.php中的非對象屬性第 162 行
和
注意:嘗試獲取 C:\\xampp\\htdocs\\seo\\seo.php 中第 163 行頁面權限:0 域權限:0 外部鏈接中的非對象屬性:
這是代碼
$accessID = " xxxx ";
$secretKey = " xxxxxxxx";
$domain = "$sig";
$expire_in = time() + 500;
$SignIn = $accessID."n".$expire_in;
$binarySignature = hash_hmac('sha1', $SignIn, $secretKey, true);
$urlSafeSignature = urlencode(base64_encode($binarySignature));
$data = "103079215140";
$curlURL = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$data."&AccessID=".$accessID."&Expires=".$expire_in."&Signature=".$urlSafeSignature;
$Domains = array($domain);
$Domai = json_encode($Domains);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $Domai
);
$ch = curl_init($curlURL);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close( $ch );
$result = json_decode($response,true);
$pageAuthority=round($result[0]->upa,0);
$domainAuthority=round($result[0]->pda,0);
$externalLinks=$result[0]->ueid;
echo "Page Authority:".$pageAuthority."<br/>";
echo "Domain Authority:".$domainAuthority."<br/>";
echo "External Links:".$externalLinks."<br/>";
您正在使用:
$result = json_decode($response,true);
^^^^ here
根據手冊:
當為 TRUE 時,返回的對象將被轉換為關聯數組。
所以結果將是一個數組,並且沒有對象。
所以你需要:
$result[0]['upa']
// etc.
$result[0]
可能不是一個對象。
嘗試在 json_decode 之后使用 print_r 打印該變量的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.