1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| function IsJSONValid($json) {
$string = json_decode(file_get_contents($json), true);
$key = array_keys($string); // Clé dynamique en cas de changement de structure du JSON
if (count($string[$key[0]]) > 0) {
return true;
} else {
return false;
}
}
foreach ($cas_tab as $cas) {
$json_export = "{\"MyJSON\":[";
$parameters = array();
$file_output = 'MYJSON_'.$cas.'.json';
foreach ($layers_tab as $layers) {
$file_input = 'JSON'.$layers.'.json';
if (file_exists($file_input) && IsJSONValid($file_input)) {
$json = file_get_contents($file_input);
$json_content = json_decode($json, true);
$json_key = array_keys($json_content);
foreach ($json_content[$json_key[0]] as $value) {
// Traitements
// $parameters[$id] = ...
}
}
}
$json_export .= json_encode($parameters);
$json_export .= "]}";
if (count($parameters) > 0) {
echo "\r\n[ ".count($parameters)." IDs traités ] Génération du fichier";
file_put_contents($file_output, $json_export);
echo " => OK";
@file_put_contents(URL_LOG_FILE, count($parameters)." IDs traités\r\n", FILE_APPEND);
}
} |
Partager