0
我正在研究一個項目,以根據ISBN號碼搜索書籍的價格。大多數情況下,它會每隔一段時間工作一段時間,而我會收到嘗試獲取非客體屬性的時間。它發生在第16行(我現在無法解決它,或者我會複製粘貼確切的消息)。php搜索試圖獲取非對象的屬性
01: <?php
02:
03: function search($query){
04:
05: $Amazon = "http://www.amazon.com/dp/".$query;
06: $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=amazon%20".$query."%20buy%20new.%20price";
07:
08: $body = file_get_contents($url);
09: if (is_null(json_decode($body)))
10: {
11: $myArray = "a";
12: }
13: else
14: {
15: $json = json_decode($body);
16: $stuff = $json->responseData->results[0]->content;
17:
18:
19: $myArray = str_split($stuff);
20: }
21:
22: $out = '$';
23:
24: for ($i = 0; $i <= sizeof($myArray) - 1; $i++)
25: {
26: if ($myArray[$i] == '$')
27: {
28: while($myArray[$i] != '.')
29: {
30: $out = $out.$myArray[$i+1];
31: $i++;
32: }
33: $out = $out.$myArray[$i+1].$myArray[$i+2];
34: break;
35: }
36: }
37: if ($out == '$')
38: {
39: $out = "Amazon does not sell this book";
40: $amazon1=$out;
41: //print_r($out);
42: echo "<br>";
43: }
44: else
45: {
46:
47: $amazon1 ="Buy new from "."<a href=$Amazon>Amazon</a>"." for ".$out;
48: echo "<br>";
49:
50: }
這不是整個代碼只是開始。發生問題的地方。
廣告更多的信息,像錯誤描述和你的輸入。我認爲你的錯誤是在行「$ stuff = $ json-> responseData-> results [0] - > content;」 。所以很可能你的$ body可能是非json格式或者只是空的。 – 2015-03-18 21:54:47