Bonjour,
Le code dépend de ce que contient ton json, et de ce que tu veux afficher.
Supposons que tes données json soient dans un fichier json de la forme :
[{"nom":"Dupont", "prenom": "Jean", "date": "22/11/2021"},
{"nom":"Martin", "prenom": "Pierre", "date": "23/11/2021"}]
Supposons que le fichier json soit à l'url 'http://localhost:8888/z/z394.json'.
La page suivante va lire le json et l'afficher dans un tableau html (une balise <table>) qui sera inséré dans l'élément de la page ayant pour id "container" :
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<style>
th,td {border:1px solid #000;}
</style>
</head>
<body>
<div id="container">
</div>
<script>
function insertTHAndTD(tr,b)
{
let th=document.createElement("TH");
let td=document.createElement("TD");
th.appendChild(document.createTextNode(b[0]));
tr.appendChild(th);
td.appendChild(document.createTextNode(b[1]));
tr.appendChild(td);
}
function insertTR(table,a)
{
let tr=document.createElement("TR");
a.forEach(b=>insertTHAndTD(tr,b));
table.appendChild(tr);
}
async function load()
{
let u='http://localhost:8888/z/z394.json';
let o=await (await fetch(u)).json();
let table=document.createElement("TABLE");
o.forEach(a=>insertTR(table,Object.entries(a)));
document.getElementById("container").appendChild(table);
}
load();
</script>
</body>
</html>
Amicalement,