Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code
PHP code to parse json:
<?php
$url = "http://xxx.com/request-url?type=json";
$string = file_get_contents($url);
$json = json_decode($string);
if (count($json)) {
echo $json->book->title;
} else {
echo "No book found";
}
?>
Example json response:
{"book":[{"title":"Good day"}]}
Because of single array, i've removed foreach: foreach($json->book as $books)
I tried:
$json->book->title,
$json->title,
$json[book][title],
$json[title].
All not working.
Any help?