简体   繁体   English

php错误:试图获取非对象的属性

[英]php error : Trying to get property of non-object

Not able to process this error as I am getting this as my output enter code here无法处理此错误,因为我在此处输入代码时收到此错误

Notice: Trying to get property of non-object in C:\\xampp\\htdocs\\seo\\seo.php on line 161 Notice: Trying to get property of non-object in C:\\xampp\\htdocs\\seo\\seo.php on line 162注意:第161行尝试获取C:\\xampp\\htdocs\\seo\\seo.php中非对象的属性 注意:尝试获取C:\\xampp\\htdocs\\seo\\seo.php中的非对象属性第 162 行

and

Notice:Trying to get property of non-object in C:\\xampp\\htdocs\\seo\\seo.php on line 163 Page Authority:0 Domain Authority:0 External Links:注意:尝试获取 C:\\xampp\\htdocs\\seo\\seo.php 中第 163 行页面权限:0 域权限:0 外部链接中的非对象属性:

and this is the code这是代码

$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/>";

You are using:您正在使用:

$result = json_decode($response,true);
                                ^^^^ here

According to the manual :根据手册

When TRUE, returned objects will be converted into associative arrays.当为 TRUE 时,返回的对象将被转换为关联数组。

So the result will be an array and there will be no objects.所以结果将是一个数组,并且没有对象。

So you need:所以你需要:

$result[0]['upa']
// etc.
$result[0]

is probably not an object.可能不是一个对象。

try using print_r to print the contents of that variable after json_decode.尝试在 json_decode 之后使用 print_r 打印该变量的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM