everyone!
I'm working on a movie website(which obviously not completed). I want to know how to export data from an API and select an array from JSON data on PHP. In this case, I want to output the title of the movie but it seems to not working. I get this error: Notice: Trying to get property of non-object. From the error, I know that I'm trying to output an object, not a string but I don't know how to resolve it.
Here's my index.php file:
<?php
require_once('includes/variables.php');
?>
<!DOCTYPE html>
<html>
<body>
<?php
echo $movieNameList->data->movies[1]->id;
?>
</body>
</html>
includes/variables.php file:
<?php
$getMovieList = file_get_contents('http://ift.tt/1xsOjG3');
$movieNameList = json_decode($getMovieList[0]);
?>
http://ift.tt/1xsOjG3 file if you're lazy:
{
"status":"ok",
"status_message":"Query was successful",
"data":{
"movie_count":4220,
"limit":2,
"page_number":1,
"movies":[
{
"id":4247,
"url":"https:\/\/yts.to\/movie\/rem-by-mtv-2014",
"imdb_code":"tt4066748",
"title":"R.E.M. by MTV",
"title_long":"R.E.M. by MTV (2014)",
"slug":"rem-by-mtv-2014",
"year":2014,
"rating":8,
"runtime":107,
"genres":[
"Documentary"
],
"language":"English",
"mpa_rating":"Unknown",
"background_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/rem_by_mtv_2014\/background.jpg",
"small_cover_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/rem_by_mtv_2014\/small-cover.jpg",
"medium_cover_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/rem_by_mtv_2014\/medium-cover.jpg",
"state":"ok",
"torrents":[
{
"url":"https:\/\/yts.to\/torrent\/download\/1F28D13F40AE91AECC58D649F5F9D84D29321632.torrent",
"hash":"1F28D13F40AE91AECC58D649F5F9D84D29321632",
"quality":"720p",
"seeds":1063,
"peers":544,
"size":"812.23 MB",
"size_bytes":851680192,
"date_uploaded":"2015-06-28 08:49:09",
"date_uploaded_unix":1435438149
},
{
"url":"https:\/\/yts.to\/torrent\/download\/DED26397FD36DFC932BB5EEEC82D25204699943C.torrent",
"hash":"DED26397FD36DFC932BB5EEEC82D25204699943C",
"quality":"1080p",
"seeds":247,
"peers":419,
"size":"1.65 GB",
"size_bytes":1766838835,
"date_uploaded":"2015-06-28 22:55:41",
"date_uploaded_unix":1435488941
}
],
"date_uploaded":"2015-06-28 08:49:06",
"date_uploaded_unix":1435438146
},
{
"id":4245,
"url":"https:\/\/yts.to\/movie\/bigfoot-county-2012",
"imdb_code":"tt2108605",
"title":"Bigfoot County",
"title_long":"Bigfoot County (2012)",
"slug":"bigfoot-county-2012",
"year":2012,
"rating":2.9,
"runtime":82,
"genres":[
"Horror",
"Mystery"
],
"language":"English",
"mpa_rating":"R",
"background_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/bigfoot_county_2012\/background.jpg",
"small_cover_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/bigfoot_county_2012\/small-cover.jpg",
"medium_cover_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/bigfoot_county_2012\/medium-cover.jpg",
"state":"ok",
"torrents":[
{
"url":"https:\/\/yts.to\/torrent\/download\/25E5FBDAD49BFD067EEB7778EF1CED753E0E608C.torrent",
"hash":"25E5FBDAD49BFD067EEB7778EF1CED753E0E608C",
"quality":"720p",
"seeds":324,
"peers":183,
"size":"693.01 MB",
"size_bytes":726671831,
"date_uploaded":"2015-06-27 14:02:07",
"date_uploaded_unix":1435370527
}
],
"date_uploaded":"2015-06-27 14:02:06",
"date_uploaded_unix":1435370526
}
]
},
"@meta":{
"server_time":1435498431,
"server_timezone":"Pacific\/Auckland",
"api_version":2,
"execution_time":"12.3 ms"
}
}
Aucun commentaire:
Enregistrer un commentaire