Ich versuche, etwas mit Yelp API2Fehler mit Yelp API Ausgang
$response = json_decode($data);
, die Daten in einem PHP-Objektformat zurück zu tun, die etwa wie folgt aussieht:
stdClass Object
(
[region] => stdClass Object
(
[span] => stdClass Object
(
[latitude_delta] => 0.28083237848028
[longitude_delta] => 0.23501544732261
)
[center] => stdClass Object
(
[latitude] => 31.335313781127
[longitude] => -92.786144296672
)
)
[total] => 736
[businesses] => Array
(
[0] => stdClass Object
(
[is_claimed] => 1
[rating] => 4
[mobile_url] => http://m.yelp.com/bizzzz?utm_campaign=yelp_api&utm_medium=api_v2_search&utm_source=toQu_qgvu90-Z7dQuZOWMQ
[rating_img_url] => https://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png
[review_count] => 147
[name] => Name here
[rating_img_url_small] => https://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png
[url] => http://www.yelp.com/biz/zzz?utm_campaign=yelp_api&utm_medium=api_v2_search&utm_source=toQu_qgvu90-Z7dQuZOWMQ
[categories] => Array
(
[0] => Array
(
[0] => Chinese
[1] => chinese
)
)
[phone] => 5123355555
[snippet_text] => My family and I went to HAO-Q Asian Kitchen for the first time before a performance of our children in Aladdin. We all happen really love Asian cuisine....
[image_url] => https://s3-media3.fl.yelpcdn.com/bphoto/XS5NjGCdn3s14_efs9w5rw/ms.jpg
[snippet_image_url] => http://s3-media4.fl.yelpcdn.com/photo/ZxVY3kdLGl6AyAblYbIRgQ/ms.jpg
[display_phone] => +1-512-338-5555
[rating_img_url_large] => https://s3-media2.fl.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png
[id] => kitchen-austin
[is_closed] =>
[location] => stdClass Object
(
[city] => Austin
[display_address] => Array
(
[0] => 123 Street
[1] => Ste 113
[2] => Far West
[3] => Austin, TX 78731
)
[geo_accuracy] => 8
[neighborhoods] => Array
(
[0] => Far West/Northwest Hills
)
[postal_code] => 78731
[country_code] => US
[address] => Array
(
[0] => 3742 Far W Blvd
[1] => Ste 113
)
[coordinate] => stdClass Object
(
[latitude] => 31.356237
[longitude] => -92.758041
)
[state_code] => TX
)
)
Ich möchte Ausgang ein einige Ergebnisse mit Limit:
Die Ausgabe ist in Ordnung, aber ich bekomme auch immer die folgenden Fehler für jede ite Ration der Schleife und jeden Wert:
Notice: Undefined offset: 10 in /mypath/YelpTest.php on line 94 Notice: Trying to get property of non-object in /mypath/YelpTest.php on line 94
Und ich habe auf eine solche Linie ist:
echo $response->businesses[$x]->name;
Was bin ich?
Warum überprüfen Sie es in jeder Schleife wenn (! array_key_exists ($ x, $ Anfrage-> Unternehmen)) {...? – itzmukeshy7
@ itzmukeshy7 Umm ... Um sicherzustellen, dass '$ Anfrage-> Unternehmen [$ x]' existiert. :) Das liegt daran, dass 'for ($ x = 0; $ x <$ limit; $ x ++)' sich nicht auf die Größe '$ request-> businesses' verlässt. Also müssen wir sicherstellen, dass der Array-Schlüssel '$ x' existiert, deshalb hat das Array einen Wert unter diesem Index. –
Aber warum machen wir es komplex, wenn wir es nur durch die Aktualisierung der $ Limit mit count ($ response-> Unternehmen) nach meiner Antwort – itzmukeshy7