--- title: PerformanceEntry.toJSON() slug: Web/API/PerformanceEntry/toJSON tags: - API - Method - Méthode - Performance Timeline API - PerformanceEntry - Reference - Performance Web translation_of: Web/API/PerformanceEntry/toJSON ---
La méthode toJSON()
permet de sérialiser l'objet PerformanceEntry
courant et renvoie une représentation JSON de l'objet.
{{AvailableInWorkers}}
let jsonObj = perfEntry.toJSON();
Aucun.
json
PerformanceEntry
.L'exemple suivant montre l'utilisation de la méthode toJSON()
.
function run_PerformanceEntry() { console.log("Support de PerformanceEntry ..."); if (performance.mark === undefined) { console.log("... performance.mark n'est pas pris en charge"); return; } // Crée quelques entrées de performance via la méthode mark() performance.mark("Begin"); do_work(50000); performance.mark("End"); // Utilise getEntries() pour itérer à travers chaque entrée. let p = performance.getEntries(); for (let i = 0; i < p.length; i++) { console.log("Entry[" + i + "]"); check_PerformanceEntry(p[i]); } } function check_PerformanceEntry(obj) { let properties = ["name", "entryType", "startTime", "duration"]; let methods = ["toJSON"]; for (let i = 0; i < properties.length; i++) { // On vérifie chaque propriété let supported = properties[i] in obj; if (supported) console.log("..." + properties[i] + " = " + obj[properties[i]]); else console.log("..." + properties[i] + " = N'est pas pris en charge"); } for (let i = 0; i < methods.length; i++) { // On vérifie chaque méthode let supported = typeof obj[methods[i]] == "function"; if (supported) { let js = obj[methods[i]](); console.log("..." + methods[i] + "() = " + JSON.stringify(js)); } else { console.log("..." + methods[i] + " = N'est pas pris en charge"); } } }
Spécification | Statut | Commentaire |
---|---|---|
{{SpecName('Performance Timeline Level 2', '#dom-performanceentry-tojson', 'toJSON')}} | {{Spec2('Performance Timeline Level 2')}} | Définition initiale de la méthode toJSON() . |
{{Compat("api.PerformanceEntry.toJSON")}}