我目前正在使用Google Places api,它会在引号中返回json。我正在尝试访问“照片”数组中的“ photo_reference”元素,并且一直在使用附带的代码,但是它一直返回null,我不知道为什么($response
是我存储我的位置的地方json)。
$response["results"][1]["photos"]["photo_reference"];
"results" : [
{
"formatted_address" : "525 W 28th St, Los Angeles, CA 90007, USA",
"geometry" : {
"location" : {
"lat" : 34.0265698,
"lng" : -118.2766572
},
"viewport" : {
"northeast" : {
"lat" : 34.02787052989272,
"lng" : -118.2752304701073
},
"southwest" : {
"lat" : 34.02517087010728,
"lng" : -118.2779301298927
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "73f56efe009cf4f46fab07e380e89fb1024f2dda",
"name" : "Grinder",
"opening_hours" : {
"open_now" : true
},
"photos" : [
{
"height" : 1080,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/111289966799928187791/photos\"\u003eRomeo C\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAYZeA7hp-fV6SUytgcjrEbTeOTDarmxhYYUoOUixAKCMhsJGyQdSnTl_LYmBGfcGjH44BfLmDJDV325flXgjCMHa8WCsKFBciYUT6hYUG0YesO5FxkClNpSDH-gPjOj5kEhBYB8hWZbWG-o20qvN9mfwiGhROzzx8GZWVS17R5NOBx7ZiJUTEug",
"width" : 1920
}
],
"place_id" : "ChIJGZfInOfHwoARtMA9n87JMK8",
"plus_code" : {
"compound_code" : "2PGF+J8 Los Angeles, California, USA",
"global_code" : "85632PGF+J8"
},
"price_level" : 1,
"rating" : 4.3,
"reference" : "ChIJGZfInOfHwoARtMA9n87JMK8",
"types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
"user_ratings_total" : 645
},
答案 0 :(得分:1)
由于["photos"]
有一个您需要使用的子数组...
$response["results"][0]["photos"][0]["photo_reference"]
始终值得使用print_r()
并按照结构进行操作以确定各个数组的位置。