aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/body/json/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/fr/web/api/body/json/index.html')
-rw-r--r--files/fr/web/api/body/json/index.html86
1 files changed, 0 insertions, 86 deletions
diff --git a/files/fr/web/api/body/json/index.html b/files/fr/web/api/body/json/index.html
deleted file mode 100644
index 121768d6ea..0000000000
--- a/files/fr/web/api/body/json/index.html
+++ /dev/null
@@ -1,86 +0,0 @@
----
-title: Body.json()
-slug: Web/API/Body/json
-tags:
- - API
- - BODY
- - Experimental
- - Fetch
- - JSON
- - Méthode
- - Reference
-translation_of: Web/API/Body/json
----
-<div>{{APIRef("Fetch")}}</div>
-
-<p>La méthode <strong><code>json()</code></strong> de {{domxref("Body")}} lit un Stream {{domxref("Response")}} jusqu'au bout. Elle retourne une promesse qui s'auto-résout en renvoyant le corps de la requête parsée au format {{jsxref("JSON")}}.</p>
-
-<h2 id="Syntaxe">Syntaxe</h2>
-
-<pre class="brush: js">response.json().then(function(data) {
- // faire quelque chose avec les données
-});</pre>
-
-<h3 id="Paramètres">Paramètres</h3>
-
-<p>Aucun.</p>
-
-<h3 id="Valeur_de_retour">Valeur de retour</h3>
-
-<p>Une promesse résolue contenant le corps de la requête (au format JSON) converti sous la forme d'un objet JavaScript. Cet objet peut correspondre à n'importe quel contenu représentable dans le format JSON -- un objet, un tableau, une chaîne de caractère, un nombre…</p>
-
-<h2 id="Exemple">Exemple</h2>
-
-<p>Dans l'exemple <a href="https://github.com/mdn/fetch-examples/tree/master/fetch-json">fetch json</a> (lancer <a href="http://mdn.github.io/fetch-examples/fetch-json/">cet exemple</a>), nous créons une nouvelle requête en utilisant le constructeur {{domxref("Request.Request", "Request()")}}, puis utilisons celle-ci pour récupérer un fichier <code>.json</code>. Lorsque l'appel à <strong>fetch </strong>réussit, on lit les données et on les parse en utilisant <code>json()</code> pour les convertir en un objet JS, puis enfin on utilise les valeurs de l'objet obtenu pour les insérer dans une liste de noeuds, de manière à afficher nos produits. </p>
-
-<pre>const myList = document.querySelector('ul');
-const myRequest = new Request('products.json');
-
-fetch(myRequest)
- .then(response =&gt; response.json())
- .then(data =&gt; {
- for (const product of data.products) {
- let listItem = document.createElement('li');
- listItem.appendChild(
- document.createElement('strong')
- ).textContent = product.Name;
- listItem.append(
- ` can be found in ${
- product.Location
- }. Cost: `
- );
- listItem.appendChild(
- document.createElement('strong')
- ).textContent = `£${product.Price}`;
- myList.appendChild(listItem);
- }
- });</pre>
-
-<h2 id="Spécifications">Spécifications</h2>
-
-<table class="standard-table">
- <tbody>
- <tr>
- <th scope="col">Spécification</th>
- <th scope="col">Status</th>
- <th scope="col">Comment</th>
- </tr>
- <tr>
- <td>{{SpecName('Fetch','#dom-body-json','Body.json()')}}</td>
- <td>{{Spec2('Fetch')}}</td>
- <td>Définition initiale</td>
- </tr>
- </tbody>
-</table>
-
-<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
-
-<p>{{Compat("api.Body.json")}}</p>
-
-<h2 id="Voir_aussi">Voir aussi</h2>
-
-<ul>
- <li><a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
- <li><a href="/en-US/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
- <li><a href="/en-US/docs/Web/HTTP">HTTP</a></li>
-</ul>