I have some json data that I would like to parse using PHP.
I would like to extract:
ID,NAME,DESC,ADDRESS (full),PHONE and HOURS.
I have tried.
$json = json_encode( $value, true );
foreach($json['results'] as $result) {
echo 'Title: ' . $result['general']['name'] . '<br />';
}
but getting following error:
PHP Warning: Illegal string offset 'results' in ...
PHP Warning: Invalid argument supplied for foreach() in ....
Here is the JSON data that I want to parse.
"ok":true,
"query":"decarli",
"page":0,
"count":100,
"total":1,
"time":"2013-01-31 00:57:40",
"results":[
{
"id":"decarli-restaurant",
"factualId":"f8990729-3ae7-4efa-8037-38fa899b07ea",
"outOfBusiness":false,
"publishedAt":"2012-03-09 10:35:51",
"general":{
"name":"Decarli Restaurant",
"timeZone":"EST",
"desc":"Decarli is an ambitious restaurant created by Jana and Paul Decarli, a husband and wife team who along with their professional staff, are dedicated to food, wine, and providing an excellent dining experience.
Paul, a longtime Oregonian and a graduate of Western Culinary Institute, developed his expertise at many of Portland\u00e2\u20ac\u2122s top restaurants including Paragon, Fratelli, Saucebox, and Tuscany Grill where he was Executive Chef.
Jana, an Oregon native and University of Oregon graduate, established her outstanding service skills and standards at San Francisco\u00e2\u20ac\u2122s esteemed 42 Degrees and Portland\u00e2\u20ac\u2122s Bluehour.
Decarli is committed to showcasing the state\u00e2\u20ac\u2122s considerable bounty of seasonal ingredients. Paul\u00e2\u20ac\u2122s culinary style draws on his Swiss\/Italian-American roots to create food that is at once sophisticated and rustic.
The restaurant\u00e2\u20ac\u2122s interior reflects the couple\u00e2\u20ac\u2122s approach to food and wine\u00e2\u20ac\u201dwarm, inviting, thoughtful and authentic. The 4000 square foot space features restored Douglas Fir floors, exposed brick walls, and a soaring beam and rafters ceiling punctuated with skylights. A highlight of the dining room is a large brass chandelier salvaged from downtown Portland\u00e2\u20ac\u2122s historic Benson Hotel. An open kitchen overlooks the comfortable bar area.
We invite you to join us soon.",
"website":"http:\/\/decarlirestaurant.com"
},
"location":{
"address1":"4545 SW Watson Ave",
"address2":"",
"city":"Beaverton",
"region":"OR",
"country":"US",
"postcode":"97005",
"longitude":-122.80611,
"latitude":45.48648
},
"phones":{
"main":"503-641-3223",
"fax":null
},
"hours":{
"mon":{
"start":"closed",
"end":"closed"
},
"tue":{
"start":"04:30pm",
"end":"10:00pm"
},
"wed":{
"start":"04:30pm",
"end":"10:00pm"
},
"thu":{
"start":"04:30pm",
"end":"10:00pm"
},
"fri":{
"start":"04:30pm",
"end":"11:00pm"
},
"sat":{
"start":"04:30pm",
"end":"11:00pm"
},
"sun":{
"start":"05:00pm",
"end":"09:00pm"
},
"holidaySchedule":""
},
"businessType":"Restaurant"
}
]
}