2015-11-01 71 views
1

獲取錯誤消息 - 注意:試圖獲取非對象的屬性我試圖用YELP API進行實驗/學習,但我遇到了一個簡單的錯誤消息,我似乎無法弄清楚。在此之後:https://github.com/Yelp/yelp-api/tree/master/v2/php使用Yelp API進行試驗PHP

function query_api($term, $location) {  
$response = json_decode(search($term, $location)); 
$business_id = $response->businesses[0]->id; 

print sprintf(
    "%d businesses found, querying business info for the top result \"%s\"\n\n",   
    count($response->businesses), 
    $business_id 
); 

$response = get_business($business_id); 

print sprintf("Result for business \"%s\" found:\n", $business_id); 
print "$response\n"; 

}

調用函數

$longopts = array(
"term::", 
"location::", 
); 

$options = getopt("", $longopts); 

$term = $options['term'] ?: ''; 
$location = $options['location'] ?: ''; 

query_api($term, $location); 

回答

3

該通知表明$response不是一個對象,你試圖訪問不存在的屬性businesses
使用var_dump($response)獲取有關此變量的信息。