I have the following .json file
{
"Filmes": [
{
"Uuid": "",
"ImdbId": "tt0023331",
"Title": "Pesn o geroyakh",
"Year": "1983",
"Director": "Joris Ivens",
"Actors": " Joris Ivens, Joris Ivens",
"Url": {
"Poster": "https:\/\/www.imdb.com\/title\/tt0023331\/mediaviewer\/rm3586657792?ref_=tt_ov_i",
"Location": ""
}
}
]
}
{
"Filmes": [
{
"Uuid": "aa-bb-cc-dd",
"ImdbId": "tt0015724",
"Title": "Dama de noche",
"Year": "1993",
"Director": "Eva López Sánchez",
"Actors": "Rafael Sánchez Navarro, Cecilia Toussaint, Miguel Córcega",
"Url": {
"Poster": "https:\/\/www.imdb.com\/title\/tt0015724\/mediaviewer\/rm615620352?ref_=tt_ov_i",
"Location": ""
}
}
]
}
And this is the code that the JSON file generates:
// 4. Llamada a la funcion read_id()
$res = $filmes->read_id($filmes->id);
// 5. Obtiene la cantidad de registros almacenados
$num =$res->rowCount();
// 6. Check si hay registros
if ($num > 0)
{
// 7. Vector-Objeto Filmes
$filmes_arr = array();
$filmes_arr['Filmes'] = array();
while ($row = $res->fetch(PDO::FETCH_ASSOC))
{
extract($row);
$filmes_item = array(
'Uuid' => $uuid_atto,
'ImdbId' => $tconst,
'Title'=> $primaryTitle,
'Year'=> $startYear,
'Director' => $director,
'Actors' => $actors,
'Url' => array(
'Poster' => $urlPoster,
'Location'=> $urlMovie)
);
// 8. Volcar los datos de filmes_item a "data"
array_push($filmes_arr['Filmes'], $filmes_item);
}
// 9. Convertir a JSON para imprimir
echo json_encode($filmes_arr, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
file_put_contents($ruta, json_encode($filmes_arr, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE), FILE_APPEND);
} else {
// Sin registros
file_put_contents($ruta, json_encode(array('Message' => null), JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
}
But when I read with the PHP script:
$data = file_get_contents("/var/www/html/Json/filmes_id.json");
$imdb = json_decode($data, true);
foreach ($imdb as $imdbs)
{
$id = ($imdbs[0]['ImdbId']);
print_r($imdbs);
}
Only the ImdbId reads: tt0023331. For the ImdbId: tt0015724 and I return null.
I realized that only the first JSON object performs the reading.