mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/LMSGI-2024-25.git
synced 2025-11-09 18:03:06 +01:00
28 lines
874 B
HTML
28 lines
874 B
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<script>
|
|
function convertirJSON() {
|
|
// Definir un JSON como string
|
|
let jsonString = '{ "producto": "Laptop", "precio": 800 }';
|
|
|
|
// Convertir el string JSON a objeto
|
|
let objeto = JSON.parse(jsonString);
|
|
|
|
// Mostrar las propiedades en la consola
|
|
console.log("Producto:", objeto.producto);
|
|
console.log("Precio:", objeto.precio);
|
|
|
|
// Mostrar el resultado en la página
|
|
document.getElementById("resultado").innerText =
|
|
"Producto: " + objeto.producto + "\nPrecio: " + objeto.precio + " €";
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<button onclick="convertirJSON()">Convertir JSON</button>
|
|
<pre id="resultado"></pre>
|
|
</body>
|
|
</html>
|