Skip to content

Commit

Permalink
print json in html
Browse files Browse the repository at this point in the history
  • Loading branch information
andritowmega authored Jan 9, 2024
1 parent 11c588a commit 2e9265a
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion js/1.1/easyfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ class EasyFetch {
}
return "";
}
printJSONinHTML(jsonObj, parentElement) {
var outputHTML = '<ul>';

for (var key in jsonObj) {
if (jsonObj.hasOwnProperty(key)) {
outputHTML += '<li>';
outputHTML += '<strong>' + key + ':</strong> ';

if (typeof jsonObj[key] === 'object') {
// Recursivamente imprimir sub-objetos
imprimirJSONenHTML(jsonObj[key], outputHTML);
} else {
// Imprimir valores simples
outputHTML += jsonObj[key];
}

outputHTML += '</li>';
}
}

outputHTML += '</ul>';

// Agregar HTML al elemento padre
parentElement.innerHTML = outputHTML;
}
}
let easyFetch = new EasyFetch();


0 comments on commit 2e9265a

Please sign in to comment.