I am trying to extract the full_name value from the below json. I have been able to extract from the "query" section using this code.
echo $data->query->params->granularity;
This prints out neighbourhood.
But I am unable to echo the full_name. Im guessing this is because I have to do something different because of the [] but I'm new to this and not at sure what to do.
None of these seem to work.
foreach ($data['places'] as $item) { ough!
echo $item->result->places->contained_within->attributes->full_name;
echo $item->result->places->full_name;
echo $item->result->full_name;
echo $item->full_name;
}
Any help would be greatly appreciated.
{
"query": {
"params": {
"accuracy": 0,
"coordinates": {
"coordinates": [
-122.42284884,
37.76893497
],
"type": "Point"
},
"granularity": "neighborhood"
},
"type": "reverse_geocode"
},
"result": {
"places": [
{
"attributes": {
},
"bounding_box": {
"coordinates": [
[
[
-122.42676492,
37.75983003
],
[
-122.420736,
37.75983003
],
[
-122.420736,
37.77226299
],
[
-122.42676492,
37.77226299
]
]
],
"type": "Polygon"
},
"contained_within": [
{
"attributes": {
},
"bounding_box": {
"coordinates": [
[
[
-122.51368188,
37.70813196
],
[
-122.35845384,
37.70813196
],
[
-122.35845384,
37.83245301
],
[
-122.51368188,
37.83245301
]
]
],
"type": "Polygon"
},
"country": "United States",
"country_code": "US",
"full_name": "San Francisco, CA",
"id": "5a110d312052166f",
"name": "San Francisco",
"place_type": "city"
}
],
"country": "United States",
"country_code": "US",
"full_name": "Mission Dolores, San Francisco",
"id": "cf7afb4ee6011bca",
"name": "Mission Dolores",
"place_type": "neighborhood"
}
]
}
}
$item->full_namemight work hard to say without seeing full JSONprint_r()is a little more verbose and will help you determine how to get each variable. pastebin.com/3hyWTNGu