可捕获的致命错误:类 stdClass 的对象无法转换为字符串/无返回


Catchable fatal error: Object of class stdClass could not be converted to string / No return

问题是$price什么都不返回。

我正在使用 https://github.com/PHPGangsta/GoogleAuthenticator 作为代码的 TOTP 部分。

我试图在$price中使用 settype((,但似乎它并没有真正起作用。

如果我将$obj->数据->价格[0]->价格更改为$obj->数据。我收到此错误

可捕获的致命错误:无法将类 stdClass 的对象转换为字符串

<?php
$secret ="(Verify Secret)";
$api = "(API Key)";
require_once 'GoogleAuthenticator.php';
$ga = new PHPGangsta_GoogleAuthenticator();
$oneCode = $ga->getCode($secret);
$itemName=str_replace(array(' ','"','''','''''',''''),array('%20',null,null,null,null),$_GET['name']);
$url = "https://bitskins.com/api/v1/get_item_price/?api_key=" . $api . "&code=" . $oneCode . "&names=" . $itemName . "&delimiter=!END!";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$obj = curl_exec($curl);
$obj = json_decode(curl_exec($curl));
curl_close($curl);
$price = $obj->data->prices[0]->price;
echo "Price: ".$price."<br>";
echo "itemName: ".$itemName."<br>";
echo "url: ".$url;
?>

你做了什么样的调试?您是否对声明的每个变量进行了var_dump(),以查看返回的内容?

我查看了位皮肤 api,我没有看到"get_item_price"是一个选项。

确定你不是故意使用get_price_data_for_items_on_sale吗?

嗯,这有点尴尬,因为问题是我很快就禁用了 API 访问并且忘记再次打开它。