🏠 Accueil ◀️ TP Précédent TP Suivant ▶️

TP8B - Lecture et Affichage des Données JSON

Manipulation de fichiers JSON avec PHP (simulé en JS)

📁 Chargement de données JSON

En PHP réel: file_get_contents('etudiant.json') + json_decode()

En JavaScript: fetch('etudiant.json') + .json()

Chargement des données en cours...

1. Contenu brut du fichier JSON

Cliquez sur "Afficher JSON brut" pour voir le contenu du fichier

2. Données structurées

3. Analyse des données

0
Total étudiants
0
Âge moyen
0
Avec formation
0
Avec matières

4. Recherche et filtrage

PHP vs JavaScript
// EN PHP
$json_data = file_get_contents('etudiant.json');
$etudiants = json_decode($json_data, true);

foreach ($etudiants as $etudiant) {
    echo "Nom: " . $etudiant['nom'];
    echo "Âge: " . $etudiant['age'];
}

// EN JAVASCRIPT
fetch('etudiant.json')
    .then(response => response.json())
    .then(data => {
        data.forEach(etudiant => {
            console.log(etudiant.nom);
            console.log(etudiant.age);
        });
    });

// LES DEUX FONCTIONNENT SIMILAIREMENT
// PHP: côté serveur, JavaScript: côté client