However I am new to JSON, I have been trying to do this for a few days and the tutorials i have found all seem simpilar than what I have, so your advice is appreciated.
list.json
[
{
"rating": "9.2",
"link": "http://www.imdb.com/title/tt0111161/",
"name": "The Shawshank Redemption",
"rank": "1",
"year": "1994"
},
{
"rating": "9.2",
"link": "http://www.imdb.com/title/tt0068646/",
"name": "The Godfather",
"rank": "2",
"year": "1972"
},
{
"rating": "9.0",
"link": "http://www.imdb.com/title/tt0071562/",
"name": "The Godfather: Part II",
"rank": "3",
"year": "1974"
}
]
I have then got as far as the following:
<?php
$list = file_get_contents('list.json');
$json = json_decode($list);
?>
I have tried a few ways to use this data but had no luck, i know that i need to put the data into a php array.
$films = array( 'rating' => $json->rating, 'link' => $json->link, 'name' => $json->name, 'rank' => $json->rank, 'year' => $json->year );
I tried to use the above and attempted to print
$films['name'];in a foreach loop, but this also did not work.
Advice required, Thanks.

New Topic/Question
Reply




MultiQuote





|